VISUAL STUDIO   Windows Mac

.NET Standard

PDF for offline use
Related Links:

Let us know how you feel about this

Translation Quality


0/250

last updated: 2017-04

Using .NET Standard Library Projects to share code

The .NET Standard Library is a formal specification of .NET APIs that are intended to be available on all .NET runtimes. The motivation behind the Standard Library is establishing greater uniformity in the .NET ecosystem. ECMA 335 continues to establish uniformity for .NET runtime behavior, but there is no similar spec for the .NET Base Class Libraries (BCL) for .NET library implementations.

You can think of it as a simplified, next generation of Portable Class Library. It is a single library with a uniform API for all .NET Platforms including .NET Core. You just create a single .NET Standard Library and use it from any runtime that supports .NET Standard Platform.

Xamarin Studio

.NET Standard library projects can be created in Xamarin Studio 6.2, by first creating a Portable Library project:

Once the project has been created, right-click and open the Project Options window. In the General section the project can be converted to .NET Standard and set to use a specific version in the Platform drop-down list:

You can then create a NuGet package to share the library with other developers.

Visual Studio for Mac Walkthrough

This section walks through how to create and use a .NET Standard Library using Visual Studio for Mac. Refer to the .NET Standard Library Example section for a complete implementation.

Creating a .NET Standard Library

Adding a .NET Standard Library to your solution is fairly straight forward.

  1. In the Add New Project dialog, select the .NET Core category and then select Class Library(.NET Core).

    Note: This template will be renamed to .NET Standard in a future version of Visual Studio for Mac.

    Create a .NET Core class library

  2. The .NET Standard Library project will appear as shown in the Solution Explorer. The Dependencies node will indicate that the library uses the NETStandard.Library.

    Dependencies node in the solution indicates .NET Standard

Editing .NET Standard Library Settings

The .NET Standard Library settings can be viewed and changed by right-clicking on the project and selecting Options as shown in this screenshot:

Edit .NET Standard target framework in Project Options

Inside you can change your version of netstandard by changing the Target Framework dropdown value.

Additionally: You can edit the .csproj directly to change this value.

Visual Studio (Windows) Walkthrough

This section walks through how to create and use a .NET Standard Library using Visual Studio. Refer to the .NET Standard Library Example section for a complete implementation.

Creating a .NET Standard Library

Visual Studio 2017

Adding a .NET Standard Library to your solution is fairly straight forward.

  1. In the Add New Project dialog, select the .NET Standard category and then select Class Library(.NET Standard).

  2. The .NET Standard Library project will appear as shown in the Solution Explorer. The Dependencies node will indicate that the library uses the NETStandard.Library.

Editing .NET Standard Library Settings

The .NET Standard Library settings can be viewed and changed by right-clicking on the project and selecting Properties as shown in this screenshot:

Inside you can change your version of netstandard by changing the Target Framework dropdown value.

Additionally: You can edit the .csproj directly to change this value.

Using .NET Standard Library

Once a .NET Standard Library has been created, you can add a reference to it from any compatible Application or Library project in the same way you normally add references. In Visual Studio, right-click on the References node and choose Add Reference... then switch to the Solution : Projects tab as shown:

Visual Studio for Mac Walkthrough

This section walks through how to create and use a .NET Standard Library using Visual Studio for Mac. Refer to the .NET Standard Library Example section for a complete implementation.

Creating a .NET Standard Library

Adding a .NET Standard Library to your solution is fairly straight forward.

  1. In the Add New Project dialog, select the .NET Core category and then select Class Library(.NET Core).

    Note: This template will be renamed to .NET Standard in a future version of Visual Studio for Mac.

  2. The .NET Standard Library project will appear as shown in the Solution Explorer. The Dependencies node will indicate that the library uses the NETStandard.Library.

Editing .NET Standard Library Settings

The .NET Standard Library settings can be viewed and changed by right-clicking on the project and selecting Options as shown in this screenshot:

Inside you can change your version of netstandard by changing the Target Framework dropdown value.

Additionally: You can edit the .csproj directly to change this value.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.