我有一个预先存在的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在图书馆项目中的优势
发布评论