简体   繁体   English

.NET Core是.NET标准的“实现”吗?

[英]Is .NET Core an “Implementation” of .NET Standard?

I'm still pretty confused about how .NET Core and .NET Standard relate to each other. 我仍然对.NET Core和.NET Standard如何相互关联感到困惑。

From what I understand, .NET Standard is an interface definition (not dissimilar in the way the Katana is an implementation of OWIN). 据我所知,.NET Standard是一个接口定义(与Katana是OWIN的实现方式不同)。 .NET Framework will implement versions of .NET Standard. .NET Framework将实现.NET Standard的版本。

Is this correct so far? 到目前为止这是正确的吗?

.NET Core bundles up its dependencies inside it. .NET Core将其依赖项捆绑在其中。 Those dependencies will use the .NET Standard interface's implementation. 这些依赖项将使用.NET Standard接口的实现。 That may be the .NET Framework, Mono or something else. 这可能是.NET Framework,Mono或其他东西。

ASP Core is .NET Core with "Web" stuff referenced. ASP Core是.NET Core,引用了“Web”内容。 Pretty much just a Visual Studio template in the sense that it can all by built up from a .NET Core console application. 几乎只是一个Visual Studio模板,它可以通过.NET Core控制台应用程序构建。

Am I still close to on track? 我还在接近正轨吗?

Finally, if I can creating a new, green-field application then .NET Core should be the favoured technology (assuming that I don't need any of the .NET Framework only assemblies). 最后,如果我可以创建一个新的绿色字段应用程序,那么.NET Core应该是受欢迎的技术(假设我不需要任何仅.NET Framework程序集)。

Last question, can I reference .NET Framework assemblies in the GAC from a .NET Core project? 最后一个问题,我可以从.NET Core项目中引用GAC中的.NET Framework程序集吗?

Cheers 干杯

My understanding is that the .NET Core is implementing the .NET Standard . 我的理解是.NET Core正在实现.NET Standard

So .NET Standard is more like a specification and .NET Core is an actual framework which implements that specification. 因此, .NET Standard更像是规范, .NET Core是实现该规范的实际框架。

.NET Standard is also implemented by other frameworks like as .NET Framework or Xamarin (and ASP.NET Core which is built on the top of .NET Core ). .NET Standard也由其他框架等作为实现.NET FrameworkXamarin (和ASP.NET Core ,其是建立在顶部.NET Core )。


Here is offficial explanation : 这是有效的解释

How is .NET Standard different from .NET Core? .NET Standard与.NET Core有何不同?

.NET Standard is a specification that covers which APIs a .NET platform has to implement. .NET Standard是一个规范,涵盖了.NET平台必须实现的API。

.NET Core is a concrete .NET platform and implements the .NET Standard. .NET Core是一个具体的.NET平台,它实现了.NET标准。


.NET Standard : .NET标准

The .NET Standard is a formal specification of .NET APIs that are intended to be available on all .NET runtimes. .NET标准是.NET API的正式规范,旨在提供给所有.NET运行时。

The various .NET runtimes implement specific versions of .NET Standard. 各种.NET运行时实现.NET Standard的特定版本。


Introducing .NET Standard : 介绍.NET标准

.NET Standard is a set of APIs that all .NET platforms have to implement. .NET Standard是一组所有.NET平台必须实现的API。 This unifies the .NET platforms and prevents future fragmentation. 这统一了.NET平台并防止了未来的碎片。

.NET Standard 2.0 will be implemented by .NET Framework, .NET Core, and Xamarin. .NET Standard 2.0将由.NET Framework,.NET Core和Xamarin实现。 For .NET Core, this will add many of the existing APIs that have been requested. 对于.NET Core,这将添加许多已请求的现有API。


Introducing .NET Core : 介绍.NET Core

.NET Core is essentially a fork of the NET Framework .NET Core本质上是.NET Framework的一个分支

Another way to look at it: The .NET Framework has essentially two forks. 另一种看待它的方法:.NET Framework基本上有两个分叉。 One fork is provided by Microsoft and is Windows only. 一个分叉由Microsoft提供,仅适用于Windows。 The other fork is Mono which you can use on Linux and Mac. 另一个分支是Mono,你可以在Linux和Mac上使用它。


For more details please read: 有关详细信息,请阅读:

  1. Yes, .NET Core is a platform / runtime that implements a version of .NET Standard. 是的,.NET Core是一个实现.NET Standard版本的平台/运行时。

If you build a library that targets a version of .NET Standard, it can be used on any runtime that implements this or a higher version of .NET Standard. 如果您构建一个面向.NET Standard版本的库,则可以在任何实现此版本或更高版本.NET Standard的运行时上使用它。 This applies to .NET Core as well as mono (=> Xamarin), UWP (.NET Native) and .NET Framework. 这适用于.NET Core以及mono(=> Xamarin),UWP(.NET Native)和.NET Framework。

  1. The detail of distribution doesn't really matter.. technically .NET Core < 2.0 relies on the way NETStandard.Library is built but that is changing for 2.0. 分发的细节并不重要..从技术上讲,.NET Core <2.0依赖于构建NETStandard.Library的方式,但是2.0的变化。

  2. ASP.NET Core is "just" a set of libraries and tooling atop a version of .NET Standard (pre 2.0 also a version of .NET Framework) that it requires to run on. ASP.NET Core是“一定”的一组库和工具,它们在.NET标准版本(2.0之前的版本也是.NET Framework)上运行。 This means you can build ASP.NET Core applications for both .NET Core and .NET Framework - potentially even other runtimes if they support the required level of .NET Standard. 这意味着您可以为.NET Core和.NET Framework构建ASP.NET Core应用程序 - 如果它们支持所需的.NET Standard级别,甚至可能是其他运行时。

  3. For new projects, it makes sense to evaluate what your needs are. 对于新项目,评估您的需求是有意义的。 .NET Core has a different servicing policy than .NET Framework and .NET Framework still has components and API that aren't going to be included in .NET Core - for example WinForms and WPF. .NET Core具有与.NET Framework不同的服务策略,.NET Framework仍然具有不会包含在.NET Core中的组件和API - 例如WinForms和WPF。

    For new library projects, it makes sense to target .NET Standard instead of .NET Framework wherever possible to ensure reusability in more types of projects. 对于新的库项目,尽可能以.NET Standard而不是.NET Framework为目标是有意义的,以确保在更多类型的项目中可重用。

Simple answer is yes : 简单的答案是肯定的

.NET Core implements the .NET Standard Library, and therefore supports .NET Standard Libraries. .NET Core实现了.NET标准库,因此支持.NET标准库。

And ASP.NET Core built on .NET Core. ASP.NET Core构建于.NET Core之上。

But : this does not mean that all ASP.NET Core apps support .NET Standard. 但是 :这并不意味着所有ASP.NET核心应用程序都支持.NET Standard。 ASP.NET Core apps can run on .NET Core or on the full .NET Framework. ASP.NET Core应用程序可以在.NET Core或完整的.NET Framework上运行。 If an app has the full .NET Framework as a target platform it may have dependencies on libraries, that don't support .NET Standard. 如果应用程序将完整的.NET Framework作为目标平台,则它可能依赖于库,而不支持.NET Standard。

The other answers are great and cover the how , but I think the key to really understanding .NET Standard is the why . 其他答案很棒,涵盖了如何 ,但我认为真正理解.NET标准的关键是原因

What is .NET Standard actually for? .NET Standard实际上是什么用途?

The purpose of .NET Standard is to allow developers to write their library and general purpose code in such a way that it can then be used by any applications they write, no matter which platform the application using that code targets (web, desktop, mobile, service etc.). .NET Standard的目的是允许开发人员编写他们的库和通用代码,使其可以被他们编写的任何应用程序使用,无论使用该代码的应用程序使用哪个平台 (Web,桌面,移动) ,服务等)。

This is needed because .NET has forked and evolved into many flavours (principally full .NET Framework, .NET Core and Xamarin). 这是必需的,因为.NET已经分叉并演变成多种风格(主要是完整的.NET Framework,.NET Core和Xamarin)。 Currently, if you want to write some code that encapsulates for example, some key business logic, and then use that code in both the desktop app, the mobile app and the website then that is difficult to achieve. 目前,如果您想编写一些封装的代码,例如一些关键业务逻辑,然后在桌面应用程序,移动应用程序和网站中使用该代码,那么很难实现。

Write once, run anywhere 写一次,随处运行

The idea of .NET Standard is that if you write your code to target just the APIs in .NET Standard, then it should work on any platform that has a version of .NET installed that implements the .NET Standard. .NET标准的想法是,如果您编写的代码仅针对.NET Standard中的API,那么它应该适用于安装了.NET版本以实现.NET Standard的任何平台。

You don't write your whole app in .NET Standard, because you will still need platform or .NET version specific features (such as windows forms control libraries, Xamarin forms controls, file system access, web security, etc.), but if you write your library code to target .NET Standard you'll know that it can be easily shared between different apps on different platforms and that it should work on those platforms if they have a .NET Standard implementing version of .NET installed. 您没有在.NET Standard中编写整个应用程序,因为您仍然需要平台或.NET版本特定的功能(例如Windows窗体控件库,Xamarin窗体控件,文件系统访问,Web安全性等),但是如果您编写的库代码以.NET Standard为目标,您将知道它可以在不同平台上的不同应用程序之间轻松共享,并且如果它们安装了.NET标准版本的.NET,它应该可以在这些平台上运行。

The ["Why do we need a standard?" [“为什么我们需要标准?” section of this MSDN blog by Immo Landewerth][1] covers this well. 由Immo Landewerth撰写的这篇MSDN博客的部分内容[1]涵盖了这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM