.NET Standard Library Support for Xamarin
Today, we are extremely pleased to release support for .NET Standard Libraries for all Xamarin applications. This includes creating and consuming local .NET Standard Libraries, but also adding .NET Standard Libraries from NuGet directly to your Xamarin apps. It’s now easier than ever to share code across all .NET platforms, including the recently introduced .NET Core and ASP.NET Core platforms.
What is .NET Standard?
The .NET Standard Library is a formal specification of .NET APIs that are intended to be available on all .NET runtimes. You can think of it as a simplified, yet expanded, Portable Class Library. It is a single library with a uniform API for all .NET Platforms including .NET Core. You just create a single .NET Standard Library and use it from any runtime that supports .NET Standard Platform.
Consuming .NET Standard NuGets & Assemblies
A lot of libraries have recently added .NET Standard support, enabling them to support .NET Core applications. It’s now possible to add a NuGet to Xamarin applications that supports .NET Standard in both Xamarin Studio and Visual Studio. For instance, here’s the preview release of Windows Azure Storage that supports .NET Standard 1.6:
As you can see, it targets the Standard library. Xamarin Studio and Visual Studio will simply add the reference to the netstandard folder when the NuGet is installed:
Getting Started with .NET Standard
To create or consume .NET Standard libraries in your Xamarin applications, ensure that you’re running Visual Studio 2015 Update 3 and are updated to Xamarin 4.1.2 for Visual Studio in the Stable release channel.
In Visual Studio, File->New Project and select the standard Portable Class Library (PCL) template located in the “Visual C#” section.
This PCL now needs to be upgraded to target the .NET Standard Library, which can be found in the projects properties.
This will change the project type and the APIs that the project can access. netstandard currently has seven versions of API coverage. Below is a useful chart to guide you through what platforms support which APIs. This can be adjusted any time in the project properties, similar to how you can change the
Profile of a PCL after creating it.
Finally, simply add the new .NET Standard Library to any Xamarin project just like any other reference!
The ability to create .NET Standard Libraries in Xamarin Studio on macOS will be available in the future, but today we are pleased to release Xamarin Studio 6.0.2 which supports consuming and compiling these libraries.
For a full breakdown of .NET Standard Libraries, including a full comparison to Portable Class Libraries, be sure to read through the official .NET Standard Library documentation.