.Net Framework, Core, and Standard
The distinction between these three concepts of .Net Framework, Core, and Standard, has long lay in a foggy corner of my brain saying “Danger! You do not understand the future of the primary technologies you use for everything!”. So I was glad when recently I was forced into understanding these things when I tried to create a NuGet package.
By far the best post I have found on this is from the .Net blog; Introducing .NET Standard.
So to explain, imagine you are making an
Acme.Utilities library which you want to publish as a package. You build it in .Net Framework 4.5, and pack it up.
You go to test your package by starting a new Console App and importing it. You feel that Visual Studio 2017 is twisting your arm into making a Console App using .Net Core, so you go for that. Unsurprisingly, when you import your package, it complains that your app and the package are not compatible - this is because .Net Core 1.x and .Net Framework 4.5 are “not compatible” (please excuse this simplification for now).
So now you’re thinking, “Well, do I have to make a copy of my package code for every single framework I want to target?” - No!
What to do
To integrate with the .Net Framework and with .Net Core, your library project needs to target .Net Standard, check out this kickin’ table (source):
|Universal Windows Platform||10.0||10.0||10.0||10.0||10.0||10.0.16299||10.0.16299||10.0.16299|
|Windows Phone Silverlight||8.0|
When you are making a new class library project in VS, you may have noticed that you can pick between “Classic Windows Desktop”, “.Net Core”, and “.Net Standard”. I would say that if you want interoperability, then .Net Standard is always the one to go for.
You should aim to support the lowest .Net Standard version you possibly can, bearing in mind that some of the features you want won’t be available in lower Standard versions. For example, I make use of
Path.DirectorySeparatorChar in one project, and this API is only available in Standard 1.3+
In essence, .Net Standard gives you a way of writing .Net code which can work in multiple different calling frameworks as long as they support the API standard which you wrote it to.