.NET Standard与.NET Core [英] .NET Standard vs .NET Core

查看:90
本文介绍了.NET Standard与.NET Core的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了.NET Standard和.NET Core之间的区别,但是我真的不知道区别是什么,何时选择.NET Standard库项目以及何时选择.NET Core库项目。



我已经读到.NET Standard是为了确保无论使用什么平台,一组API始终可用(只要该平台与我选择的.NET标准版本)。如果我没记错的话,这意味着我可以创建.NET Standard的类库,然后在与我选择的.NET Standard版本兼容的任何平台上使用它。



使用.NET Core,我已经读到它也打算用于跨平台使用,因此,如果我选择.NET Core库,似乎也可以在许多平台上使用它,就像.NET一样。标准。



所以最后,我看不出有什么区别。我什么时候应该使用哪个?它们之间有什么区别?

解决方案

我将尝试进一步阐明您的疑问并扩展Jon Skeet的答案。



.NET Standard是规范,因此针对特定.NET Standard版本编译的库可以在不同的.NET Standard实现中使用。



如我的另一条评论所述,.NET标准与其他.NET标准实现(.NET Core,.NET Framework等)之间的关系的一个很好的类比是



任何针对 NetCore10 的对象都可以访问 INetStandard15 API NetCore10 特定 API(例如 DotNetHostPolicy )。



当然,该库不能用于其他 INetStandard15 实现( NetCore10 不能转换为 NetFramework462 Mono46 )。



如果您只需要访问 INetStandard15 API(并以该规范而不是具体的框架为目标),您的库就可以由实现它的任何框架(< c $ c> NetCore10 , NetFramework462 等)



注意:在最初的类比中,David Fowler使用了.NET Standard版本和框架实现的接口。我认为,使用接口和类可以更直观,并且可以更好地表示规范和具体实现之间的关系。


I have read about the difference between .NET Standard and .NET Core, but I really don't know what the difference is, or when to choose a .NET Standard library project and when to choose a .NET Core library project.

I have read that .NET Standard is to ensure that a set of APIs are always available, no matter the platform used (as long as that platform is compatible with the .NET Standard version that I have chosen). If I'm not mistaken, this means that I can create a class library of .NET Standard and then use it on any platform that is compatible with the .NET Standard version that I have chosen.

With .NET Core, I have read that it is intended for cross-platform use too, so if I choose a .NET Core library it seems that I can use it on many platforms too, just like .NET Standard.

So at the end, I don't see the difference. When should I use which? What is the difference between them?

解决方案

I will try to further clarify your doubts and extend Jon Skeet answer.

.NET Standard is a specification, so a library compiled for a specific .NET Standard version can be used in different .NET Standard implementations.

As said in my other comment, a good analogy for the relationship between .NET Standard and other .NET Standard Implementations (.NET Core, .NET Framework, etc) is this gist by David Fowler: .NET Standard versions are Interfaces, while frameworks are implementations of those interfaces.

This simplified diagram may help to understand this relationship:

Anything targetting NetCore10 has access to INetStandard15 APIs and NetCore10 specific APIs (such as DotNetHostPolicy).

Of course this library cannot be used in different INetStandard15 implementations (NetCore10 is not convertible to NetFramework462 or Mono46).

If you, instead, need access only to INetStandard15 APIs (and target that specification instead of a concrete framework) your library may be used by any framework which implements it (NetCore10, NetFramework462, etc.)

Note: in the original analogy David Fowler used interfaces for both .NET Standard versions and frameworks implementations. I believe that using interfaces and classes is, instead, more intuitive and better represents the relationship between specifications and concrete implementations.

这篇关于.NET Standard与.NET Core的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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