2

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?)

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
g.pickardou
  • 32,346
  • 36
  • 123
  • 268

1 Answers1

6

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.

Guillaume Perrot
  • 4,278
  • 3
  • 27
  • 37
  • 4
    Note that `PackageTargetFallback` is deprecated in favour of `PackageAssetFallback` in .NET Standard 2.0 and .NET Core 2.0, which behaves a little bit differently. – Martin Ullrich Sep 18 '17 at 19:00
  • I had no success with PackageAssertFallback, only PackageTargetFallback is working. Should this considered as a bad sign? – g.pickardou Sep 20 '17 at 07:12
  • You are using .net standard 1.4 in the question but PackageAssetFallback is for 2.0. Did you update to 2.0 in the mean time? – Guillaume Perrot Sep 20 '17 at 19:20
  • PS: Microsoft.AppCenter is the 1.0.0 versions of the MobileCenter packages and have first class support for .NET standard now. So this work around is not needed anymore in the new packages. – Guillaume Perrot Nov 20 '17 at 19:48