In the latest version of Visual Studio (2017) you have at least four different templates for creating a Class Library:
- Class Library (Universal Windows)
- Class Library (.NET Framework)
- Class Library (.NET Core)
- Class Library (.NET Standard)
Additionally, you may also find a Portable Class Library template, as well as one for a Xamarin Class Library. Since the .NET Core and .NET Standard templates are relatively new, they can cause some confusion. The terms .NET Core and .NET Standard are also sometimes inconsistently used to mean either the same or a different thing. To clear up some of the confusion, Microsoft created this diagram.
(source: https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/)
In this diagram, you see that .NET Standard is a positioned as a set of APIs that all .NET platforms have to implement. This unifies the .NET platforms and prevents future fragmentation. .NET Standard 2.0 will be implemented by .NET Framework, .NET Core, and Xamarin. For .NET Core, this will add many of the existing APIs that have been requested. Now that .NET Standard 2.0 is mentioned, there must also be a .NET Standard 1.0. There is, and you can find the details on GitHub, but the specification is pretty limited. There have been several releases since 1.0, and we are currently at version 1.6. A list of supported platforms for each version can be found here: https://docs.microsoft.com/en-us/dotnet/standard/net-standard. As you can see, the lower the version, the more platforms implement it. The downside being that less functionality is available in the earlier versions. Microsoft shipped Visual Studio 2017 RTM with .NET Core 1.X support, and the expectation is that .NET Core 2.0 will be available in 2017 Q3. Also .NET Standard 2.0 will be released in the same timeframe. While there’s no 1:1 concurrency between .NET Core and .NET Standard, it does make sense to release them simultaneously. As you can see on the road map, it’s not a requirement.
To be clear, a project targeted at a specific version of .NET Standard will not be able to make use of features that are not included in that revision of the standard. However, this doesn’t mean you can’t take dependencies on other assemblies, or APIs published by other vendors. But it does mean that any dependencies you take must also include support for your version of .NET Standard. A class library project that is looking for wide distribution, you should try to use the .NET Standard template since in theory it can run with .NET Core, .NET Framework, Xamarin, etcetera. If the class library is mainly for internal use, choosing .NET Standard may not be as much of a concern.
The following images list the different dependencies for each of the two project templates.
What about PCL?
.NET Standard can be considered as the next generation of Portable Class Libraries (PCL). The .NET Standard improves on the experience of creating portable libraries by curating a standard BCL and establishing greater uniformity across .NET runtimes as a result. A library that targets .NET Standard is a PCL or a “.NET Standard-based PCL”. PCL profiles and .NET Standard were created for similar purposes but also differ in key ways. Both define APIs that can be used for binary code sharing. However:
- .NET Standard is a curated set of APIs, while PCL profiles are defined by intersections of existing platforms.
- .NET Standard linearly versions, while PCL profiles do not.
- PCL profiles represents Microsoft platforms while the .NET Standard is agnostic to platform.
EF Core and ASP.NET Core
Together with .NET Core, Microsoft is also investing in other frameworks that target .NET Standard. Entity Framework Core (EF Core) is a lightweight, extensible, and cross-platform version of Entity Framework and can be used in multiple .NET platforms, including .NET Core 2.0 and .NET Framework 4.6 or newer. EF Core 2.0 Preview 2 is available since June 2017: https://blogs.msdn.microsoft.com/dotnet/2017/06/28/announcing-ef-core-2-0-preview-2/. At Build 2017, Microsoft released an initial preview version of ASP.NET Core 2.0. Since June 2017, there is a Preview 2 version of the ASP.NET Core 2.0 framework and Visual Studio tools for you to try: https://blogs.msdn.microsoft.com/webdev/2017/06/28/introducing-asp-net-core-2-0-preview-2/
So far, Microsoft is able to have ASP.NET Core and EF Core follow the same release cycle as .NET Core.
Summary
A .NET Core Class Library is built upon the .NET Standard. If you want to implement a library that is portable to the .NET Framework, .NET Core and Xamarin, choose a .NET Standard Library. If you only want to target .NET Core, choose the .NET Core library.
- .NET Standard is a set of APIs that all .NET platforms have to implement. This unifies the .NET platforms and prevents future fragmentation.
- .NET Standard 2.0 will be implemented by .NET Framework, .NET Core, and Xamarin.
- .NET Standard 2.0 includes a compatibility shim for .NET Framework binaries, significantly increasing the set of libraries that you can reference from your .NET Standard libraries.
- .NET Standard will replace Portable Class Libraries (PCLs) as the tooling story for building multi-platform .NET libraries.
If you need help deciding which framework to target, check out this page: https://docs.microsoft.com/en-us/dotnet/standard/choosing-core-framework-server
More information: https://docs.microsoft.com/en-us/dotnet/standard/net-standard
Leave a Comment