Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantages of netcoreapp2.0 vs netstandard2.0 for a library project

I have a preexisting dotnet 4.6.2 solution that comprises of two outer projects (to be ported at the same time) and a shared core library.

I need to choose the core assembly's TargetFramework, which could either be netcoreapp2.0 or netstandard2.0.

Since it won't be executable, or referenced by any external project, are there any advantages one way or the other?

like image 810
Jon Bates Avatar asked Aug 24 '17 16:08

Jon Bates


People also ask

What is the difference between creating .NET STD library and .NET Core library?

NET Core, you can build cross-platform console apps and ASP.NET Core Web applications and cloud services. . NET Standard: This is the set of fundamental APIs (commonly referred to as base class library or BCL) that all . NET implementations must implement.

What is the difference between .NET Framework core and .NET standard class library project types?

NET Standard is an API specification that defines, for a given version, what Base Class Libraries must be implemented. . NET Core is a managed framework that is optimized for building console, cloud, ASP.NET Core, and UWP applications.

When should we use .NET Core and .NET standard class library project types?

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 applications to be compatible with your library.

How do I choose the target version of .NET standard library?

If you are not sure which version of . NET Standard you should target, go with 2.0 as it offers a balance of reach and APIs available for you to use. If your goal is to make your library usable for many frameworks as possible while gettings all the APIs you can from .


2 Answers

They differ in nature:

  • The .NET Standard is a set of APIs (standard)
  • The .NET Core Libraries are a set of libraries (implementation)

Each version of the .NET Core Librairies implements (at least) a given version of the .NET Standard, and a complete table can be found in the .NET Standard documentation. Right now, the latest versions are in sync (2.0 - 2.0), but this hasn't been and won't always be true.

The .NET Core Libraries are actually always a superset of the APIs defined in the corresponding version of the .NET Standard. There are always types and members available in the .NET Core Libraries, which are not (yet?) part of the .NET Standard. Microsoft publishes namespace-by-namespace comparisons of the available APIs.

Your library might use an API that has not yet been standardized in the .NET Standard (or might never be), but is already available in .NET Core Libraries. As an example, you might use types from the System.Drawing namespace, that will soon be available in the .NET Core Libraries, but won't be part of the .NET Standard 2.0.

So, by choosing netcoreapp2.0 over netstandard2.0, you gain access to a larger API, at the expense of compatibility.

On a general note, you should always try to target the most portable framework (here, netstandard).

If it is not an option for you, the next best thing would be to cross-target multiple frameworks from a single library, as explained here: How do you multi-target a .NET Core class library with csproj?. Many .NET Core APIs missing from the .NET Standard are also present in the (full) .NET Framework.

like image 99
Mathieu Renda Avatar answered Dec 01 '22 01:12

Mathieu Renda


NetStandard is new recommended library format that enables sharing between different frameworks(NetFramwwork, NetCore, Xamarin) so that would be the answer. https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/

like image 27
borisdj Avatar answered Dec 01 '22 00:12

borisdj