Modern applications often need to be adapted to different types of devices and operating systems, and therefore to different implementations of .NET (.NET Framework, .NET Core and Xamarin). In this case the maintaining shared code becomes a challenge. You need to understand what APIs are available and make sure that common components only work with APIs that are supported in all .NET implementations you use. The .NET Standard was created to solve this problem. Each version of .NET Standard defines a set of APIs. All .NET implementations conforming to this version must support all of these APIs.
The table below shows which .NET implementations are suitable for which tasks:
|Platform||OS||Is Open Source||Type of applications|
|.NET Standard||Any||Yes||Create libraries that can be used in any .NET implementation, including .NET Framework, .NET Core, and Xamarin.|
|.NET Framework||Windows||No||Create classic Windows and ASP.NET web applications for IIS.|
|.NET Core||Windows, Linux, macOS||Yes||Build cross-platform console apps as well as ASP.NET Core web apps and cloud services.|
|Xamarin||iOS, Android, macOS||Yes||Create mobile apps for iOS and Android, desktop apps for macOS.|
When to use .NET Standard? – Example
Let’s imagine you have an application that compares products from different sources. And your application is presented in the classic Windows Application, ASP.NET Core Web Application, and Xamarin mobile application. Obviously, these applications will have some common functionality like loading pricing, XML serialization, calculation, etc. For this purpose, you can create a shared library using the .NET Standard.
.NET Standard Versions
Each version of .NET Standard contains a certain set of APIs. Each new version of .NET Standard contains all the APIs of the previous versions and some new ones. This makes .NET Standard backwards compatible. You should remember two rules:
- Higher version = More APIs
- Lower version = more platforms
If you create a .NET Standard library that you want to share, you should always target the lowest version of .NET Standard that you can get away with. This way, you can reach the maximum amount of platforms.