Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert .NET Core 2.0 class libraries to .NET Standard

Is there a way to easily convert a class library targeting .NET Core 2.0 to .NET Standard?

If I understand it correctly, if one wants to maximize the reusability of class libraries in projects targeting different .NET frameworks e.g. .NET Framework, .NET Core, Xamarin, etc., it's a better idea to target .NET Standard -- provided that all the required APIs are available in the version of .NET Standard that will be targeted.

This is the reason why I want to convert my class libraries from .NET Core 2.0 to .NET Standard 1.6 or .NET Standard 2.0.

like image 805
Sam Avatar asked Sep 07 '17 04:09

Sam


People also ask

How do I convert .NET framework to .NET standard?

To do that, complete the following steps: In Visual Studio select Analyze and then Portability Analyzer Settings. In the General Settings window, select . NET Standard 2.0 under Target Platforms, and then choose OK.

Is .NET Core compatible with .NET standard?

NET Standard 1.3 will be compatible with apps that target . NET Framework 4.6, . NET Core 1.0, Universal Windows Platform 10.0, and any other platform that supports .

How do I use .NET standard library in .NET Core?

Open Visual Studio 2015 Go to menu click File> New> Project then choose . net Core from left menu by selecting ASP.NET Core Web Application like below image. I have chosen an ASP.NET Core sample Template, like the below image. Let's create another project as a simple class library.

Is .NET standard 2.0 compatible with .NET framework?

Broad platform support. . NET Standard 2.0 is supported on the following platforms: . NET Framework 4.6.


1 Answers

In the project file, you can point target compilation to netstandard with the exact version.

Example of Proj.csproj:

<Project Sdk="Microsoft.NET.Sdk">   <PropertyGroup>     <TargetFramework>netstandard1.6</TargetFramework>   </PropertyGroup> </Project> ... 

Microsoft provides good documentation about targeting types.

Dotnet Standard is not a framework or a library, it is an abstract set of instructions: what functionality should have System.Array, String, List, and so on. Currently, there are different implementations: .NET Framework, .NET Core, Mono, Xamarin, Windows Phone. It means that different implementations can recompile and reuse your library targeting netstandard. It is a very good choice for a NuGet package.

You can play with the versions and find the minimum function set required for your library. Each Dotnet Standard extends the functionality of the previous version. Thus, the less the targeted version is selected the more platforms your library will support.

like image 173
Artur A Avatar answered Nov 04 '22 03:11

Artur A