.NET Core 是 .NET Standard 的 "Implementation" 吗?

Is .NET Core an "Implementation" of .NET Standard?

我仍然对 .NET Core 和 .NET Standard 之间的关系感到困惑。

据我了解,.NET Standard 是一个接口定义(与 Katana 是 OWIN 的实现方式没有什么不同)。 .NET Framework 将实施 .NET Standard 版本。

到目前为止这是否正确?

.NET Core 将其依赖项捆绑在其中。这些依赖项将使用 .NET Standard 接口的实现。那可能是 .NET Framework、Mono 或其他东西。

ASP Core 是 .NET Core,引用了 "Web" 内容。几乎只是一个 Visual Studio 模板,因为它可以从 .NET Core 控制台应用程序构建。

我还接近正轨吗?

最后,如果我可以创建一个新的未开发应用程序,那么 .NET Core 应该是首选技术(假设我不需要任何仅 .NET Framework 的程序集)。

最后一个问题,我可以从 .NET Core 项目中引用 GAC 中的 .NET Framework 程序集吗?

干杯

我的理解是 .NET Core 正在实施 .NET Standard

所以 .NET Standard 更像是一个规范,.NET Core 是一个实现该规范的实际框架。

.NET Standard 也由其他框架实现,例如 .NET FrameworkXamarin(以及构建在 .NET Core 之上的 ASP.NET Core)。


Here is offficial explanation:

How is .NET Standard different from .NET Core?

.NET Standard is a specification that covers which APIs a .NET platform has to implement.

.NET Core is a concrete .NET platform and implements the .NET Standard.


.NET Standard:

The .NET Standard is a formal specification of .NET APIs that are intended to be available on all .NET runtimes.

The various .NET runtimes implement specific versions of .NET Standard.


Introducing .NET Standard:

.NET Standard is a set of APIs that all .NET platforms have to implement. This unifies the .NET platforms and prevents future fragmentation.

.NET Standard 2.0 will be implemented by .NET Framework, .NET Core, and Xamarin. For .NET Core, this will add many of the existing APIs that have been requested.


Introducing .NET Core:

.NET Core is essentially a fork of the NET Framework

Another way to look at it: The .NET Framework has essentially two forks. One fork is provided by Microsoft and is Windows only. The other fork is Mono which you can use on Linux and Mac.


更多详情请阅读:

  1. 是的,.NET Core 是一个平台/运行时间,它实现了一个版本的 .NET Standard。

如果您构建的库以某个版本的 .NET Standard 为目标,则它可以在实现此版本或更高版本的 .NET Standard 的任何 运行 时间使用。这适用于 .NET Core 以及 mono (=> Xamarin)、UWP (.NET Native) 和 .NET Framework。

  1. 分发的细节并不重要。技术上 .NET Core < 2.0 依赖于 NETStandard.Library 的构建方式,但 2.0 正在改变。

  2. ASP.NET 核心“只是”一组基于 .NET Standard 版本(2.0 之前也是 .NET Framework 的版本)的库和工具,它需要 运行上。这意味着您可以为 .NET Core 和 .NET Framework 构建 ASP.NET 核心应用程序 - 如果它们支持所需的 .NET Standard 级别,甚至可能 运行 次。

  3. 对于新项目,评估您的需求是有意义的。 .NET Core 具有与 .NET Framework 不同的服务策略,并且 .NET Framework 仍然具有不会包含在 .NET Core 中的组件和 API - 例如 WinForms 和 WPF。

    对于新的库项目,尽可能以 .NET Standard 而不是 .NET Framework 为目标是有意义的,以确保在更多类型的项目中的可重用性。

简单的回答是:

.NET Core implements the .NET Standard Library, and therefore supports .NET Standard Libraries.

并且 ASP.NET Core 基于 .NET Core 构建。

但是:这并不意味着所有 ASP.NET Core 应用程序都支持 .NET Standard。 ASP.NET 核心应用程序可以 运行 在 .NET Core 或完整的 .NET Framework 上。如果应用将完整的 .NET Framework 作为目标平台,它可能依赖于不支持 .NET Standard 的库。

其他答案很好,涵盖了如何,但我认为真正理解 .NET Standard 的关键是为什么

.NET Standard 的实际用途是什么?

.NET Standard 的目的是允许开发人员以这样的方式编写他们的库和通用代码,以便他们编写的任何应用程序都可以使用这些代码,无论应用程序是哪个平台使用该代码目标(网络、桌面、移动、服务等)。

这是必需的,因为 .NET 已经分叉并演变成多种风格(主要是完整的 .NET Framework、.NET Core 和 Xamarin)。目前,如果你想写一些代码封装一些关键的业务逻辑,然后在桌面应用程序、移动应用程序和网站中使用这些代码,那是很难实现的。

写一次,运行随处

.NET Standard 的理念是,如果您编写的代码仅针对 .NET Standard 中的 API,那么它应该可以在安装了实现 .NET Standard 的 .NET 版本的任何平台上运行。

您无需使用 .NET Standard 编写整个应用程序,因为您仍然需要平台或 .NET 版本特定的功能(例如 windows 表单控件库、Xamarin 表单控件、文件系统访问、网络安全等),但是如果你编写你的库代码以 .NET Standard 为目标,你就会知道它可以很容易地在不同平台上的不同应用程序之间共享,并且如果它们有 .NET Standard,它应该可以在这些平台上工作实施安装的 .NET 版本。

Immo Landewerth 撰写的 MSDN 博客的 ["Why do we need a standard?" 部分][1] 很好地介绍了这一点。