August 2nd, 2016

.NET Standard Library Support for Xamarin

James Montemagno
Principal Manager, Tech PM

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.

NetStandard

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:

NuGet

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:

AzureStorage

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.

AddNewPCL

This PCL now needs to be upgraded to target the .NET Standard Library, which can be found in the projects properties.

RetargetPCL

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.

Platforms

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.

Learn More

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.

Author

James Montemagno
Principal Manager, Tech PM

James Montemagno is a Principal Lead Program Manager for Developer Community at Microsoft. He has been a .NET developer since 2005, working in a wide range of industries including game development, printer software, and web services. Prior to becoming a Principal Program Manager, James was a professional mobile developer and has now been crafting apps since 2011 with Xamarin. In his spare time, he is most likely cycling around Seattle or guzzling gallons of coffee at a local coffee shop. He ...

More about author

0 comments

Discussion are closed.