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

查看:28
本文介绍了将 .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.ArrayStringList,等等.目前,有不同的实现: .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天全站免登陆