我读过关于。net Standard和。net Core的区别,但是我真的不知道区别是什么,或者什么时候选择。net Standard库项目和什么时候选择。net Core库项目。

我读过。net标准是为了确保一组api总是可用的,无论使用什么平台(只要该平台与我所选择的。net标准版本兼容)。如果我没有弄错的话,这意味着我可以创建一个。net标准的类库,然后在任何与我所选择的。net标准版本兼容的平台上使用它。

对于。net Core,我读到过它也是用于跨平台使用的,所以如果我选择一个。net Core库,似乎我也可以在许多平台上使用它,就像。net Standard一样。

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


当前回答

.NET Standard is a specification of APIs that all .NET implementations must provide. It brings consistency to the .NET family and enables you to build libraries you can use from any .NET implementation. It replaces PCLs for building shared components. .NET Core is an implementation of the .NET Standard that’s optimized for building console applications, Web apps and cloud services using ASP.NET Core. Its SDK comes with a powerful tooling that in addition to Visual Studio development supports a full command line-based development workflow. You can learn more about them at aka.ms/netstandardfaq and aka.ms/netcore.


以上,以及对这个问题中讨论的大部分内容的非常清楚的解释,可以在以下微软(MSDN - 2017年9月)的非常有用的文章中找到:.NET标准-揭开。net核心和。net标准的神秘面纱

其他回答

.NET Standard is a specification of APIs that all .NET implementations must provide. It brings consistency to the .NET family and enables you to build libraries you can use from any .NET implementation. It replaces PCLs for building shared components. .NET Core is an implementation of the .NET Standard that’s optimized for building console applications, Web apps and cloud services using ASP.NET Core. Its SDK comes with a powerful tooling that in addition to Visual Studio development supports a full command line-based development workflow. You can learn more about them at aka.ms/netstandardfaq and aka.ms/netcore.


以上,以及对这个问题中讨论的大部分内容的非常清楚的解释,可以在以下微软(MSDN - 2017年9月)的非常有用的文章中找到:.NET标准-揭开。net核心和。net标准的神秘面纱

In simple terms, .NET standard is used for writing class library projects which compiles to dll. .NET Core can be used for developing actual web applications which can run on all operating systems (Windows, Linux, MacOS). (In .NET Core 3 Microsoft has provide the functionality to develop desktop apps using WPF, but uptil now these apps will not be cross platform and will only run on windows system. In future Microsoft might make them cross-platform too) .NET standard libraries/dlls can be used in any application which uses .NET (.NET framework, .NET Core) which means that you can use .NET standard with both .NET framework and .NET core.

. net标准是一种用于。net实现的。net api规范。这样就可以为所有。net实现定义统一的BCL api集。

. net Core是. net Standard的一种实现,. net Framework是. net Standard的另一种实现。

图片来自。net博客

Federicos的回答为您提供了每个框架如何随版本发展的图形概述。看看下面这个来自微软文档的图表。

瞄准。net标准可以增加你的 平台支持,而针对一个特定的。net平台,如 .NET Core(或。net Framework)将允许您为此使用所有的平台特性 平台。

.NET Core Class library is basically a subset of .NET Framework library, which just contains fewer APIs. Sticking to .NET Core Class library makes it difficult to share code between runtimes. This code might not work for a different runtime (Mono for Xamarin), because it doesn't have the API that you need. To solve this there is .NET Standard, which is just set of specification that tells you which APIs you can use. The main purpose of .NET Standard is to share code between runtimes. And it's important that this specification is implemented by all runtimes. (.NET Framework, .NET Core and Mono for Xamarin).

所以如果你确定你的库只用于。net Core项目,你可以忽略。net Standard,但是如果你的代码有一点点可能会被。net Framework或者Mono用于Xamarin,那么最好还是坚持。net Standard

Also note that higher versions of .NET Standard contain more APIs, but lower versions are supported by more platforms. Therefore if you create a .NET Standard library that you want to share between runtimes then target the lowest version you can, which helps you reach the most platforms. For example, if you want to run on .NET Framework 4.5 and .NET Core 1.0, the highest .NET Standard version you can use is .NET Standard 1.1. Refer to this great table from the documentation for more info about it.

另外,如果你想把你的库转换成。net标准,. net可移植性分析器可以帮助你。

你是说。net Framework吗?因为。net标准是一个实现,比如。net Framework、。net Core和Xamarin。

我喜欢。net Core,因为我们可以在Linux上托管它(在我的经验中使用nginx)。它与。net框架不同,你只能在IIS上托管。在这种情况下,你可以考虑托管预算(因为windows服务器对我来说很贵)。

从开发环境的角度来看,. net核心是轻量级的。所以,你可以使用VSCode, Sublime, IDE(不仅仅是visual studio)。