我读过关于。net Standard和。net Core的区别,但是我真的不知道区别是什么,或者什么时候选择。net Standard库项目和什么时候选择。net Core库项目。
我读过。net标准是为了确保一组api总是可用的,无论使用什么平台(只要该平台与我所选择的。net标准版本兼容)。如果我没有弄错的话,这意味着我可以创建一个。net标准的类库,然后在任何与我所选择的。net标准版本兼容的平台上使用它。
对于。net Core,我读到过它也是用于跨平台使用的,所以如果我选择一个。net Core库,似乎我也可以在许多平台上使用它,就像。net Standard一样。
所以最后,我看不出有什么不同。什么时候用哪个?它们之间的区别是什么?
.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可移植性分析器可以帮助你。