引用 PCL 配置文件 111 是 PCL .NET 标准 1.1

Reference a PCL profile 111 is a PCL .NET standard 1.1

在 .NET 标准 PCL 项目中,我想引用一个针对配置文件 111 (lib\portable-win8+net45+wpa81+MonoAndroid+Xamarin.iOS10) 的私有 nuget 包

但是当我添加 nuget 包时,nuget 抱怨 nuget 包不包含与 netstandard 1.1 兼容的目标。尽管文档 https://docs.microsoft.com/fr-fr/dotnet/articles/standard/library 解释了配置文件 111 与 netstandard 1.1 兼容,并且如果引用了 Microsoft.NETCore.Portable.Compatibility 包,则可以引用,就是这种情况。

知道出了什么问题吗?我可以更新自定义 nuget 包,但不知道要更改什么。

project.json 文件中,尝试为特定的 PCL 配置文件添加 imports 指令。像这样,

"frameworks": {
  "netstandard1.1": {
    "imports": "portable-win8+net45+wpa81"
  }
}

此外,为了获得最大的兼容性,我认为您应该放弃 NuGet 包的 MonoAndroidXamarin.iOS10 规范。包管理器应该能够自行得出 Xamarin 适用性的结论。

可以找到有关 imports 指令的更多信息 here

同样的技巧适用于 .csproj 个文件。您只需要将 PackageTargetFallback 添加到您的项目文件(在 VS2017 中测试):

<PropertyGroup>
  <TargetFramework>netstandard1.1</TargetFramework>
  <PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wpa81</PackageTargetFallback>
</PropertyGroup>

有时,当尝试使用某个包时,该包不支持相应的 TargetFramework。 Imports 为您提供了一种方式来指定在这种情况下使用哪些 TargetFramework 的资产 - 因为您知道它们是兼容的。

From: https://docs.nuget.org/ndocs/schema/project.json

Imports Imports are designed to allow packages that use the dotnet TxM to operate with packages that don't declare a dotnet TxM. If your project is using the dotnet TxM then all the packages you depend on must also have a dotnet TxM, unless you add the following to your project.json in order to allow non dotnet platforms to be compatible with dotnet. If you are using the dotnet TxM then the PCL project system will add the appropriate imports statement based on the supported targets.

"frameworks": { "dotnet": { "imports" : "portable-net45+win81" } }

支持 PackageTargetFallback 的 MSBuild 语法

PackageTargetFallbacks 可能已设置在 Microsoft 目标之一(我们正在考虑)或其他目标中。

Finally, as @altso says, you can solve your problem editing the .csproj of the PCL project and add the next line:

<PackageTargetFallback Condition="'$(TargetFramework)'=='Net45'">
    $(PackageTargetFallback);portable-net45+win8+wpa81+wp8
</PackageTargetFallback >

参考:https://github.com/NuGet/Home/wiki/PackageTargetFallback-%28new-design-for-Imports%29