What is .NET Standard?

Posted 10/7/2020 by Tom Smith
LinkedIn ShareShare
More

What is .NET Standard?
In recent blog posts, we’ve talked about what both .NET Core and Blazor are; in those posts, we’ve had to mention something called the .NET Standard, but what is it?

The tl;dr (too long; didn’t read) is that the .NET Standard is a list of APIs and methods you should expect to find in .NET Framework, .NET Core, Xamarin (or any of the other “.NETs” such as Unity3D and UWP). It can be used to help develop a new .NET platform or framework.

What is a standard document?
Think about your WiFi router. It offers a number of channels, allows you to set up one or more SSID (the name of the network), and protect it with a number of security features. It operates using a specific set of frequencies, and you can expect a certain level of data transfer rates.

These are all controlled by the WiFi standard. If a router doesn’t offer features at those specific levels and rates, then it will not be allowed to carry the WiFi branding, and no one will buy it.

A similar thing can be said about Credit and Debit cards: they’re all the same physical size, have the same rounded corners, have the same magnetic stripe, and those which have a chip and/or NFC have them in the exact same place. If they didn’t match this standard, then we would need hundreds of different readers for all of the Credit and Debit cards issued by different providers, and retail payments would be a nightmare.

The .NET Standard
Immo Landwerth and his team have endeavoured to create a document which describes all of the features, APIs and methods that you can expect a .NET platform to use. If you’ve ever read the C# spec (or any other language spec), then you’ve seen something similar.

In C# development, we like to work against interfaces, these are ways of describing how some code should look rather than how it should work. You can think of the .NET Standard as an interface and .NET Framework, Core, or Mono as an implementation of that interface.

Here’s an example of the .NET Standard as an interface:

// This is an example so it isn't perfect C# code, but
// it should be enough to get the point across
interface INetStandard_1_0
{
  System;
  System.Collections;
  System.Collections.Generic;
  /* ... */
  System.IO;
  System.Linq;
  System.RegularExpressions;
  /* etc. */
}

interface INetStandard_1_1 : INetStandard_1_0
{
  System.Collections.Concurrent;
  System.Numerics;
  /* etc. */
}

inteface INetStandard_1_6 : INetStandard_1_5
{
  System.Security.Cryptography.Algorithms;
  /* etc. */
}

interface INetStandard_2_0 : INetStandard_1_6
{
  System.Data;
  System.Data.Common;
  System.Data.SqlTypes;
  /* ... */
  System.IO.Compression;
  System.IO.IsolatedStorage;
  /* etc. */
}

And here’s an example of the .NET Standard having been implemented across two different versions of .NET Framework:

public class DotNetFramework_FourPointFive : INetStandard_1_0
{
  /* Actual implementations of the APIs here */
}

public class DotNetFramework_FourPointSixPointOne : INetStandard_2_0
{
  /* Actual implementations of the APIs here */
}


Platform Support

.NET Standard platform support table as of May 2020

The above table was taken from the .NET Standard GitHub repo and is correct at the time of writing; and the blog post that is referenced is: Announcing .NET Standard 2.1

The above table shows the .NET ecosystem platforms as rows, and the .NET Standard versions as columns. As the .NET Standard version number increases, the platform support drops off.

Microsoft’s official guideline when targeting .NET Standard is to target the lowest version of the standard that you can get away with, in order to get the widest possible ecosystem platform target area.

Summary

The .NET Standard was created to ensure that .NET developers have access to the APIs that they need regardless of which of the “.NETs” that they used. It is a document which lists these APIs, and nothing more.

Links


About the Author
Jamie Taylor is a .NET Contractor, podcaster, speaker, and creator of several open-source libraries and applications.

Ready to find your next big challenge? Let's Go!