Blogs Hub

by AskGif | Dec 24, 2018 | Category :coding

What is the difference between .NET Core and .NET Standard Class Library project types?

What is the difference between .NET Core and .NET Standard Class Library project types?

<p>Question:</p> <p>In Visual Studio, there are at least 3 different types of class library you can create:</p> <p>&nbsp;</p> <p>Class Library (.NET Framework)</p> <p>Class Library (.NET Standard)</p> <p>Class Library (.NET Core)</p> <p>While the first is what we've been using for years, a major point of confusion I've been having is when to use the .NET Standard and .NET Core class library types. I've been bitten by this recently when attempting to multi-target different framework versions, and creating a unit test project.</p> <p>&nbsp;</p> <p>So, what is the difference between Class Library (.NET Standard) and Class Library (.NET Core), why do both exist, and when should we use one over the other?</p> <p>&nbsp;</p> <p>solution</p> <p>When should we use one over the other?</p> <p>&nbsp;</p> <p>The decision is a trade-off between compatibility and API access.</p> <p>&nbsp;</p> <p>Use a .NET Standard library when you want to increase the number of apps that will be compatible with your library, and you are okay with a decrease in the .NET API surface area your library can access.</p> <p>&nbsp;</p> <p>Use a .NET Core library when you want to increase the .NET API surface area your library can access, and you are okay with allowing only .NET Core apps to be compatible with your library.</p> <p>&nbsp;</p> <p>For example, a library that targets .NET Standard 1.3 will be compatible with apps that target .NET Framework 4.6, .NET Core 1.0, Universal Windows Platform 10.0, and any other platform that supports .NET Standard 1.3. The library will not have access to some parts of the .NET API, though. For instance, the&nbsp; Microsoft.NETCore.CoreCLR package is compatible with .NET Core but not with .NET Standard.</p> <p>&nbsp;</p> <p>What is the difference between Class Library (.NET Standard) and Class Library (.NET Core)?</p> <p>&nbsp;</p> <p>The Package-based frameworks section here describes the difference.</p> <p>&nbsp;</p> <p>Compatibility: Libraries that target .NET Standard will run on any .NET Standard compliant runtime, such as .NET Core, .NET Framework, Mono/Xamarin. On the other hand, libraries that target .NET Core can only run on the .NET Core runtime.</p> <p>&nbsp;</p> <p>API Surface Area: .NET Standard libraries come with everything in NETStandard.Library whereas .NET Core libraries come with everything in Microsoft.NETCore.App. The latter includes approximately 20 additional libraries, some of which we can add manually to our .NET Standard library (such as System.Threading.Thread) and some of which are not compatible with the .NET Standard (such as Microsoft.NETCore.CoreCLR).</p> <p>&nbsp;</p> <p>Also, .NET Core libraries specify a runtime and come with an application model. That's important, for instance, to make unit test class libraries runnable.</p> <p>&nbsp;</p> <p>Why do both exist?</p> <p>&nbsp;</p> <p>Ignoring libraries for a moment, the reason that .NET Standard exists is for portability; it defines a set of APIs that .NET platforms agree to implement. Any platform that implements a .NET Standard is compatible with libraries that target that .NET Standard. One of those compatible platforms is .NET Core.</p> <p>&nbsp;</p> <p>Coming back to libraries, the .NET Standard library templates exist to run on multiple runtimes (at the expense of API surface area). Obversely, the .NET Core library templates exist to access more API surface area (at the expense of compatibility) and to specify a platform against which to build an executable.</p> <p>source: https://stackoverflow.com/questions/42939454/what-is-the-difference-between-net-core-and-net-standard-class-library-project?rq=1:</p> <p>&nbsp;</p>

read more...