Convert .NET Core 2.0 class libraries to .NET Standard

后端 未结 3 462
深忆病人
深忆病人 2020-12-25 10:33

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

相关标签:
3条回答
  • 2020-12-25 11:06

    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.

    0 讨论(0)
  • 2020-12-25 11:20
    1. Go to Project Folder
    2. Open .csproj file
    3. Replace your Target Framwork

      netcoreapp2.2 TO netstandard2.0

    See this picture to more clear

    0 讨论(0)
  • 2020-12-25 11:26

    You can edit the csproj file (can be done inside VS by right-clicking on the project file) and change

    <TargetFramework>netcoreapp2.0</TargetFramework>
    

    to

    <TargetFramework>netstandard2.0</TargetFramework>
    
    0 讨论(0)
提交回复
热议问题