.NET Standard / .NET Standard Library

First, we will focus on Portable Class Library (PCL) then we will replace it with .Net Standard.
 

Portable Class Library (PCL)

 
PCL is all about sharing the code across several targeted platforms. Its main goal is to re-use the code across different types of .Net applications with targeted platforms.
 
Let’s create a new .Net Core application to reference a normal class library whether it works or not.
 
Open Visual Studio 2015 Go to menu click File> New> Project then choose .net Core from left menu by selecting ASP.NET Core Web Application like below image.
 
 
I have chosen an ASP.NET Core sample Template, like the below image.
 
 
Let’s create another project as a simple class library.
 
 
Notice that we are targeting .Net Framework 4.6.1.
 
 
Here we can see a warning while we are going to reference it in our ASP.NET Core sample application.
 
 
.Net Framework 4.6.1 is unsupported by .Net Core Application with the version of 1.0, how we can solve this. Now let’s create another class library that is portable with the specific targeting platform.
 
 
Configure the target options.
 
 
.Net Framework 4.6 is supporting the same set of portable APIs as .Net Framework 4.5, so it will automatically target to .Net Framework 4.5.
 
Go to properties of the portable class library we can see we have targeted the .Net Framework 4.5, ASP.NET Core 1.0, Windows 8
 
 
Reference it to our .Net Core Application.
 
 
According to the below diagram, we have now three different Base Class Libraries (BCL) that are targeted to specific environments. The problem here is writing code for multiple .NET platforms. It is also hard to figure out supported APIs on different platforms.
 
 
Image: blogs.msdn.microsoft.com
 
What if we have a Unified Base Class Library?
 
Here comes .NET Platform Standard as Unified Base Class Library which runs on all .NET platforms.
 

.NET Standard

 
Previously named .NET Platform, Standard is a set of APIs that work on all .NET runtimes. Code-sharing problem is now more simplified by .Net Standard. We can simply replace Portable Class Library (PCL) with .Net Standard.
 
 
Image: blogs.msdn.microsoft.com
 
With .Net Standard we are not targeting the specific platform but we are working with different versions of .Net Standard that is supported by cross-platform/environments.
 
 
We can convert our existing PCL to .Net Standard Library by Clicking on Target .Net Platform Standard as in the above picture.
 
Warning with change effect will appear, click “Yes”, it will make a change in the library.
 
 
New file named project.json will be created automatically with the target environment information.
 
 
Project.json
  1. {  
  2.    "supports": {},  
  3.    "dependencies": {  
  4.    "Microsoft.NETCore.Portable.Compatibility""1.0.1",  
  5.    "NETStandard.Library""1.6.0"  
  6. },  
  7.    "frameworks": {  
  8.    "netstandard1.5": {}  
  9. }  
  10. }   
 

.NET Standard Version

 
 
Image: blogs.msdn.microsoft.com
 
From the upper version matrix table – .NET Core 1.0 targeted the .NET Standard version 1.6 and it will work with all the lower versions of 1.0 – 1.5.
 

Summary

  • .NET Standard – Works on .NET runtimes (.NET framework, .NET core, Mono)
  • Portable Class Library (PCL) – Works on targeted .NET platforms (.NET framework 4.5, ASP .NET core 1.1, Windows 8)
References
  • https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard
  • https://docs.microsoft.com/en-us/dotnet/articles/standard/library
  • https://github.com/dotnet/standard
  • https://github.com/dotnet/standard/blob/master/docs/faq.md