.Net Standard

First let's refresh 2 things -

What are .NET implementations?

There are four primary .NET implementations that Microsoft actively develops and maintains :

.NET Core is a cross-platform implementation of .NET and designed to handle server and cloud workloads at scale. It runs on Windows, macOS and Linux

The.NET Framework is the original .NET implementation that has existed since 2002. It's the same .NET Framework that existing .NET developers have always used

Mono is a .NET implementation that is mainly used when a small runtime is required. It is the runtime that powers Xamarin applications on Android, Mac, iOS, tvOS and watchOS and is focused primarily on a small footprint. Mono also powers games built using the Unity engine.

Universal Windows Platform (UWP) is an implementation of .NET that is used for building modern, touch-enabled Windows applications and software for the Internet of Things (IoT).

what are .net runtimes?

A runtime is the execution environment for a managed program.

Again, there are 4 run times for each of the implementations.

Common Language Runtime (CLR) for -----------------> the .NET Framework

Core Common Language Runtime (CoreCLR) for -----------------> .NET Core

.NET Native for ----------------->Universal Windows Platform

The Mono runtime for -----------------> Xamarin.iOS, Xamarin.Android, Xamarin.Mac, and the Mono desktop framework

Now, lets see what is .Net standard and how it is beneficial -

.Net standard

.Net standard is a specification of .NET APIs that make up a uniform set of contracts that you compile your code against.

These contracts are implemented in each .NET implementation (.NET Core, .NET Framework, Mono, Universal Windows Platform)

This enables portability across different .NET implementations, effectively allowing your code to run everywhere.

.NET Standard is not something that you install – it is a formal specification of APIs that you can use. .NET Standard is an evolution of Portable Class Libraries.

The purpose of .NET Standard is simple: to share code between runtimes. When you want to share code between different runtimes in the .NET Ecosystem, use .NET Standard.

In short, if you target your development to .Net standards then the api's you use for development are available in all 4 implementations, it means your program will not cry when you want to switch to alternate run times.

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 keeps on growing with each version. Higher version numbers of .NET Standard mean that they contain more APIs.

On the other hand, lower versions of .Net standard are supported by more platforms.

Higher version = more APIs

Lower version = more platforms

Microsoft has done one amazing job which helps developers like us a lot...

All these versions, platforms, .net implimentations , api support etc are all concepts but in reality when you sit and start designing then one needs to know what api are supported and in which version.

.NET API Browser comes here for our rescue. https://docs.microsoft.com/en-gb/dotnet/api/


At the time of writing this blog I see -

.Net Standard 2.0 has 78 namespaces defined.

.Net core has 2.2 has 122 namespaces defined.

Home work to you - Find out those 44 namespaces which are extra in .Net core but not in .Net standard. Use the same .Net Api browser to figure this out. This will tell you that these 44 namespaces may not work in other implementations except .Net Core.

.NET Portability Analyzer

You can also analyze your current projects for compatibility with a specific .NET Standard version to see if you can convert them to .NET Standard. To do this, you can use the .NET Portability Analyzer, which is a tool from the Visual Studio Marketplace. You can use it from Visual Studio or from the command line.