.NET Standard 2.0 Support in Xamarin.Forms
This article explains how to convert a Xamarin.Forms application to use .NET Standard 2.0.
.NET Standard is a specification of .NET APIs that are intended to be available on all .NET implementations. It makes it easier to share code across desktop applications, mobile apps and games, and cloud services, by bringing identical APIs to the different platforms. For information about the platforms supported by .NET Standard, see .NET implementation support.
.NET Standard libraries are the replacement for Portable Class Libraries (PCL). However, a library that targets .NET Standard is still a PCL, and is referred to as a .NET Standard-based PCL. Certain PCL profiles are mapped to .NET Standard versions, and for profiles that have a mapping, the two library types will be able to reference each other. For more information, see PCL compatibility.
Xamarin.Forms 2.4 allows Xamarin.Forms applications to target .NET Standard 2.0 by replacing the PCL with a .NET Standard 2.0 library. This can be achieved as follows:
- Ensure .NET Core 2.0 is installed.
- Update the Xamarin.Forms solution to use Xamarin.Forms 2.4, or greater.
- Add a .NET Standard library to the solution, that targets .NET Standard 2.0.
- Delete the class that's added to the .NET Standard library.
- Add the Xamarin.Forms 2.4 (or greater) NuGet package to the .NET Standard library.
- In the platform projects, add a reference to the .NET Standard library and remove the reference to the PCL project that contains the Xamarin.Forms user interface logic.
- Copy the files from the PCL project to the .NET Standard library.
- Remove the PCL project that contains the Xamarin.Forms user interface logic.
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.