I read this article a while ago: https://blog.xamarin.com/net-standard-library-support-for-xamarin/
So, I converted all of our libraries from portable libraries to .NET Standard (1.4). I did this because the article says "This PCL now needs to be upgraded to target the .NET Standard Library, which can be found in the projects properties.".
However, I can't figure out how to build a Xamarin Forms project that targets .NET Standard. I cloned the Xamarin Forms samples, and opened up the MasterDetailPage project. I went in to the project properties and switched from portable to .NET Standard as per the instructions. Immediately, I get an error telling me that I need to opt in to NuGet 3.0 support. I'm fine with this, but how do I do it?
I found that if I remove the Xamarin Forms NuGet package, I am able to switch over to .NET Standard. However, once I have done this, I can't add the Xamarin Forms NuGet package back. It just keeps failing. Contrary to what the article says, I cannot add references to .NET Standard libraries. When I try to add a reference to existing .NET Standard libraries in my Solution, Visual Studio just gives me an error saying that the library is not compatible. Which version of .NET Standard should I be targeting for Xamarin Forms?
How do I get a .NET Standard library compiling with Xamarin Forms support?
If you wanna do it with the new Visual Studio 2017 release with csproj instead of project.json you can either use dotnet migrate CLI command or add/edit this code to your csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageTargetFallback>$(PackageTargetFallback);portable-win+net45+wp8+win81+wpa8</PackageTargetFallback>
</PropertyGroup>
</Project>
It turns out that you can get a .NET Standard project to reference the Xamarin Forms NuGet package, and therefore be able to leverage .NET Standard libraries in Xamarin Forms.
This article more or less explains how to do it. The trick is to import the portable framework in the project.json. https://xamarinhelp.com/dot-net-standard-pcl-xamarin-forms/
If you can't get it working, here is a Git sample that does work. https://github.com/adamped/XamarinForms.NetStandard.git
I was eventually able to target .NET Standard 1.4 without issues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With