.NET Standard is a formal specification of .NET APIs that are available on multiple .NET implementations. The motivation behind the .NET Standard was to establish greater uniformity in the .NET ecosystem.
.NET Core 3.0 implements .NET Standard 2.1. However, the default
dotnet new classlib template generates a project that still targets .NET Standard 2.0. To target .NET Standard 2.1, edit your project file and change the
TargetFramework property to
netstandard2.1 as shown below.
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard2.1</TargetFramework> </PropertyGroup> </Project>
To build .NET Standard libraries in Visual Studio, make sure you have Visual Studio 2019 or Visual Studio 2017 version 15.3 or later installed on Windows, or Visual Studio for Mac version 7.1 or later installed on macOS.
The following are the newly added APIs in .NET Standard 2.1.
Span<T>was added which is an array-like type that allows representing managed and unmanaged memory uniformly and supports slicing without copying.
Span<T>is a very fundamental type as it requires runtime and compiler support to be fully leveraged.
Span<T>is available as a .NET Standard compatible NuGet package
System.Memoryalready, adding this package cannot extend the members of .NET Standard types that deal with spans.
ValueTask<T>already exists and allows to return results if the operation is completed synchronously without having to allocate a new
ValueTaskthat allows reducing allocations even for cases where the operation has to be completed asynchronously, a feature that types like Socket and NetworkStream now utilize.
DbProviderFactoriesallows libraries and applications to utilize a specific ADO.NET provider without knowing any of its specific types at compile-time, by selecting among registered
DbProviderFactoryinstances based on a name, which can be read from, for example, configuration settings.
System.HashCodefor combining hash codes or new overloads on
.NET Standard is still needed for libraries that can be used by multiple .NET implementations. We recommend you target .NET Standard in the following scenarios:
netstandard2.0to share code between .NET Framework and all other implementations of .NET.
netstandard2.1to share code between Mono, Xamarin, and .NET Core 3.x.