.NET Standard vs .NET Core

I have read about the difference between .NET Standard and .NET Core, but I really don't know what the difference is, or when to choose a .NET Standard library project and when to choose a .NET Core library project.

I have read that .NET Standard is to ensure that a set of APIs are always available, no matter the platform used (as long as that platform is compatible with the .NET Standard version that I have chosen). If I'm not mistaken, this means that I can create a class library of .NET Standard and then use it on any platform that is compatible with the .NET Standard version that I have chosen.

With .NET Core, I have read that it is intended for cross-platform use too, so if I choose a .NET Core library it seems that I can use it on many platforms too, just like .NET Standard.

So at the end, I don't see the difference. When should I use which? What is the difference between them?


I will try to further clarify your doubts and extend Jon Skeet answer.

.NET Standard is a specification, so a library compiled for a specific .NET Standard version can be used in different .NET Standard implementations.

As said in my other comment, a good analogy for the relationship between .NET Standard and other .NET Standard Implementations (.NET Core, .NET Framework, etc) is this gist by David Fowler: .NET Standard versions are Interfaces , while frameworks are implementations of those interfaces.

This simplified diagram may help to understand this relationship:

NET标准接口比喻

Anything targetting NetCore10 has access to INetStandard15 APIs and NetCore10 specific APIs (such as DotNetHostPolicy ).

Of course this library cannot be used in different INetStandard15 implementations ( NetCore10 is not convertible to NetFramework462 or Mono46 ).

If you, instead, need access only to INetStandard15 APIs (and target that specification instead of a concrete framework) your library may be used by any framework which implements it ( NetCore10 , NetFramework462 , etc.)

Note: in the original analogy David Fowler used interfaces for both .NET Standard versions and frameworks implementations. I believe that using interfaces and classes is, instead, more intuitive and better represents the relationship between specifications and concrete implementations.


.NET Core is an implementation of .NET Standard. It's available on multiple operating systems, but that's not the same thing - there are other implementations of .NET Standard as well.

So if you create a .NET Core library, it will have access to things that are implemented in .NET Core, but aren't part of .NET Standard, and your library won't be compatible with other implementations of .NET Standard, such as Xamarin, Tizen, full .NET desktop framework etc.

In short: to achieve maximum portability, make your library target .NET Standard.


.NET Core Class library is basically subset of .NET Framework library, which just contains less APIs. Sticking to .NET Core Class library makes difficult to share code between runtimes. This code might not work for different runtime (Mono for Xamarin), because it doesn't have the API that you need. To solve this there is .NET Standard, which is just set of specification that tells you which APIs you can use . Main purpose of .NET Standard is to share code between runtimes. And important that this specification implemented by all runtimes.(.NET Framework, .NET Core and Mono for Xamarin).

So if you sure that you will use your library only for .NET Core projects, you can ignore .NET Standard, but if have even tiny chance that your code will be used by .NET Framework or Mono for Xamarin then better stick to .NET Standard

Also note that higher version of .NET Standard contain more APIs, but lower version supported by more platforms. Therefore if you create .NET Standard library that you want to share between runtimes then target the lowest version you can , which help you reach maximum amounts of platforms. For example, if you want to run on .NET Framework 4.5 and .NET Core 1.0, the highest .NET Standard version you can use is .NET Standard 1.1. This this great table from documentation for more info about it.

PS: Also if you want to convert you library to .NET Standard, .NET Portability Analyzer could help you with that.

链接地址: http://www.djcxy.com/p/14368.html

上一篇: 我如何迭代NSArray?

下一篇: .NET标准与.NET核心