netcoreapp2.0与netstandard2.0在图书馆项目中的优势

编程入门 行业动态 更新时间:2024-10-25 10:24:43
本文介绍了netcoreapp2.0与netstandard2.0在图书馆项目中的优势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个预先存在的dotnet 4.6.2解决方案,该解决方案由两个外部项目(要同时移植)和一个共享的 core 库组成。

I have a preexisting dotnet 4.6.2 solution that comprises of two outer projects (to be ported at the same time) and a shared core library.

我需要选择核心程序集的 TargetFramework ,可能是 netcoreapp2.0 或 netstandard2.0 。

I need to choose the core assembly's TargetFramework, which could either be netcoreapp2.0 or netstandard2.0.

既然它不能执行,或者不能被任何外部项目引用,那么有没有一种优势?

Since it won't be executable, or referenced by any external project, are there any advantages one way or the other?

推荐答案

它们的性质不同:

  • 。NET Standard 是一组API(标准)
  • 。NET核心库是一组库(实现)
  • The .NET Standard is a set of APIs (standard)
  • The .NET Core Libraries are a set of libraries (implementation)

.NET Core Librairies的每个版本都实现(至少).NET Standard的给定版本,并且完整的表可以在。NET标准文档。现在,最新版本是同步的(2.0-2.0),但这不是过去,也不会总是如此。

Each version of the .NET Core Librairies implements (at least) a given version of the .NET Standard, and a complete table can be found in the .NET Standard documentation. Right now, the latest versions are in sync (2.0 - 2.0), but this hasn't been and won't always be true.

.NET核心库是实际上,始终是.NET标准相应版本中定义的API的超集。 .NET核心库中始终有可用的类型和成员,这些类型和成员不是(但?).NET标准的一部分。微软发布了可用API的名称空间/名称空间比较。。

The .NET Core Libraries are actually always a superset of the APIs defined in the corresponding version of the .NET Standard. There are always types and members available in the .NET Core Libraries, which are not (yet?) part of the .NET Standard. Microsoft publishes namespace-by-namespace comparisons of the available APIs.

您的库可能使用的API尚未在.NET Standard中进行标准化(或者可能从未采用),但已在.NET Core库中提供。例如,您可以使用System.Drawing命名空间中的类型,该类型将很快在.NET Core库中可用,但不会成为.NET Standard 2.0的一部分。

Your library might use an API that has not yet been standardized in the .NET Standard (or might never be), but is already available in .NET Core Libraries. As an example, you might use types from the System.Drawing namespace, that will soon be available in the .NET Core Libraries, but won't be part of the .NET Standard 2.0.

因此,通过选择netcoreapp2.0而不是netstandard2.0,可以访问更大的API,而以兼容性为代价。

So, by choosing netcoreapp2.0 over netstandard2.0, you gain access to a larger API, at the expense of compatibility.

,您应该始终尝试针对最易移植的框架(此处为netstandard)。

如果您不愿意这样做,那么下一个最好的办法是从一个库中跨目标多个框架,如此处所述:如何使用csproj多目标.NET Core类库?。 (完整的).NET Framework中还存在.NET标准中缺少的许多.NET Core API。

If it is not an option for you, the next best thing would be to cross-target multiple frameworks from a single library, as explained here: How do you multi-target a .NET Core class library with csproj?. Many .NET Core APIs missing from the .NET Standard are also present in the (full) .NET Framework.

更多推荐

netcoreapp2.0与netstandard2.0在图书馆项目中的优势

本文发布于:2023-11-16 15:08:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1605384.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图书馆   优势   项目

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!