3
votes

In a .NET standard PCL project, i want to reference a private nuget package which targets profile 111 (lib\portable-win8+net45+wpa81+MonoAndroid+Xamarin.iOS10)

But when i add the nuget package, nuget complains that the nuget package does not contains targets that is compatible with netstandard 1.1. Though the doc https://docs.microsoft.com/fr-fr/dotnet/articles/standard/library explains that profile 111 is compatible with netstandard 1.1, and can be referenced if the Microsoft.NETCore.Portable.Compatibility package is referenced, which is the case.

Any idea what's wrong ? I can update the custom nuget package but don't know what to change.

3

3 Answers

3
votes

In the project.json file, try to add an imports directive for the specific PCL profile. Like this,

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

Also, for maximum compatibility, I think you should drop the MonoAndroid and Xamarin.iOS10 specifications for the NuGet package. The package manager should be able to conclude Xamarin applicability by itself.

A little more information on the imports directive can be found here.

3
votes

The same trick works with .csproj files. You just need to add PackageTargetFallback to you project file (tested in VS2017):

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

Sometimes, when attempting to use a package, the package doesn't have the appropriate TargetFramework supported. Imports provided a way for you to specify, for that case, which TargetFramework's assets to use instead - since you know they are compatible.

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" } }

MSBuild syntax to support PackageTargetFallback

PackageTargetFallbacks may have been set in one of Microsoft targets (we are considering), or other ones.

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 >

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