将.NET Core 2.0类库转换为.NET Standard [英] Convert .NET Core 2.0 class libraries to .NET Standard

查看:92
本文介绍了将.NET Core 2.0类库转换为.NET Standard的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以轻松地将面向.NET Core 2.0的类库转换为.NET Standard?

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

如果我理解正确,是否想最大化类库在针对不同.NET框架的项目中的可重用性,例如.NET Framework,.NET Core,Xamarin等,将.NET Standard作为目标是一个更好的主意-前提是所有需要的API在目标的.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.

这就是为什么要将类库从.NET Core 2.0转换为.NET Standard 1.6或.NET Standard 2.0的原因。

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.

推荐答案

在项目文件中,您可以将目标编译指向带有准确版本的 netstandard

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

Proj.csproj 的示例:

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

Microsoft提供了很好的有关定位类型的文档

Microsoft provides good documentation about targeting types.

Dotnet Standard不是框架或库,它是一组抽象的指令:哪些功能应具有 System.Array String 列表,依此类推。当前,有不同的实现: .NET Framework,.NET核心,单声道,Xamarin,Windows Phone。这意味着不同的实现可以重新编译和重用针对 netstandard 的库。对于NuGet软件包来说,这是一个很好的选择。

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.

您可以使用这些版本,并找到库所需的最小功能集。每个Dotnet标准都扩展了先前版本的功能。因此,选择的目标版本越少,您的图书馆将支持的平台越多。

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.

这篇关于将.NET Core 2.0类库转换为.NET Standard的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆