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

后端 未结 2 1681
名媛妹妹
名媛妹妹 2021-01-01 18:14

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 cho

相关标签:
2条回答
  • 2021-01-01 18:34

    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/

    0 讨论(0)
  • 2021-01-01 18:40

    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.

    0 讨论(0)
提交回复
热议问题