建议的NuGet软件包TargetFrameworks

时间:2020-04-21 06:43:27

标签: c# .net-core nuget nuget-package

我将创建一些Nuget软件包,并且试图找到有关为NuGet软件包设置目标框架的任何建议。不幸的是,我没有为此找到任何好的参考(Cross-Platform targeting文档除外,该文档指出所有库都应参考netstandard2.0)。

如果我看一下Microsoft的NuGet软件包,他们做的情况就大不相同了,下面是一些与扩展相关的软件包的示例:

  • Microsoft.Extensions.DependencyInjection.Abstractions仅指netstandard2.0
  • Microsoft.Extensions.Logging指的是netcoreapp3.1和netstandard2.0
  • Microsoft.Extensions.DependencyInjection引用netcoreapp3.1,netstandard2.1和netstandard2.0。
    • netstandard2.0使用Microsoft.Bcl.AsyncInterfaces,因此这是该目标与其他目标之间的区别。
  • Microsoft.Extensions.Hosting.Abstractions引用netcoreapp3.1和netstandard2.0
    • 这里的netstandard2.0也使用Microsoft.Bcl.AsyncInterfaces,但是不同的是,在此程序包中没有netstandard2.1引用,该引用导致引用netstandard2.1(支持异步接口)的库是否有对此非netstandard2.1库的引用?

那么,为什么几乎所有新的NuGet软件包都包含netcoreapp3.x目标框架,却不包含netstandard 2.1?我可以看到netstandard2.0的原因,但看不到包含netcoreapp3.x而不包含或代替netstandard2.1的原因。

(我之所以写netcoreapp3.x而不是netcoreapp3.0和/或netcoreapp3.1的原因是因为这是在NuGet软件包的netcoreapp3.0和netcoreapp3.1版本中完成的。)

1 个答案:

答案 0 :(得分:0)

您选择的nuget软件包目标应与项目的目标框架兼容。

一篇有用的文章,有助于了解.NET Core和.NET Standard之间的区别:Demystifying .NET Core and .NET Standard

这是一张表,显示什么.NET Core目标支持什么.NET Standard

enter image description here

Image reference

Here,您可以找到有关.NET Core 3.1所做更改的更多特定信息。

请记住,您还可以在nuget包中添加几个框架目标。