netcoreapp2.0 与 netstandard2.0 对于图书馆项目的优势 [英] Advantages of netcoreapp2.0 vs netstandard2.0 for a library project

查看:32
本文介绍了netcoreapp2.0 与 netstandard2.0 对于图书馆项目的优势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个预先存在的 dotnet 4.6.2 解决方案,它包含两个外部项目(要同时移植)和一个共享的 core 库.

我需要选择核心程序集的TargetFramework,它可以是netcoreapp2.0netstandard2.0.

既然它不能被执行,也不能被任何外部项目引用,那么有什么好处吗?

解决方案

本质不同:

.NET Core 库的每个版本(至少)实现了给定版本的 .NET Standard,完整的表格可以在 .NET 标准文档.目前,最新版本是同步的 (2.0 - 2.0),但这不是也不会总是如此.

.NET Core 库实际上始终是相应版本的 .NET Standard 中定义的 API 的超集..NET Core 库中总是有可用的类型和成员,它们(还?)不是 .NET Standard 的一部分.Microsoft 发布了可用 API 的逐个命名空间比较.>

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

因此,通过选择 netcoreapp2.0 而不是 netstandard2.0,您可以访问更大的 API,但会牺牲兼容性.

一般来说,您应该始终尝试针对最便携的框架(此处为 netstandard).

如果它不适合您,那么下一个最好的方法是从单个库中交叉定位多个框架,如下所述:如何使用 csproj 多目标 .NET Core 类库?..NET Standard 中缺少的许多 .NET Core API 也存在于(完整的).NET Framework 中.

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.

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?

解决方案

They differ in nature:

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.

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.

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.

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

On a general note, you should always try to target the most portable framework (here, netstandard).

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 对于图书馆项目的优势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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