How to use nuget package in NET standard project, which is only compatible with portable-net45+win8+wp8+wpa81?

599 views Asked by At

Context

With a few hours of boring work I've just migrated all my PCL projects to .NET standard in a Xamarin.Forms solution. (why? because it seemed like a good idea at the time)

Anyway, I had success.

As a next step I decided to add Xamarin Insights, I was directed to https://mobile.azure.com/ where I instructed to use Microsoft.Azure.Mobile.Analytics and Microsoft.Azure.Mobile.Crashes packages.

However when installing any of the packages I got this error:

Package Microsoft.Azure.Mobile.Analytics 0.15.0 is not compatible with netstandard1.4 (.NETStandard,Version=v1.4). Package 
Microsoft.Azure.Mobile.Analytics 0.15.0 supports:
 - monoandroid403 (MonoAndroid,Version=v4.0.3)
 - portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259)
 - uap10.0 (UAP,Version=v10.0)
 - xamarinios10 (Xamarin.iOS,Version=v1.0)

Question

I understand the error. Please do not tell me that I have to migrate down my all projects again back to PCL. (and give up the .NET Standard).

I have some memories that somewhere I read that there is a magical package, which I install then it provides some trick and everything will be again cool. (or am I dreaming?)

1

There are 1 answers

4
Guillaume Perrot On BEST ANSWER

You can add a fallback to your project configuration to consume a .NET standard package in a PCL project:

New csproj format:

<PropertyGroup>
  <PackageTargetFallback>portable-net45+win8+wpa81</PackageTargetFallback>
</PropertyGroup>

Old project.json format:

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

As for the "magic" package you were probably told about Microsoft.Bcl.Build but in this case I am not sure if it helps.