2
votes

I am about to create some Nuget packages and I am trying to find any recommendations for setting target frameworks for NuGet packages. Unfortunately I haven't found any good references for this (except the Cross-Platform targeting documentation which states that all libraries should reference netstandard2.0).

If I look at Microsofts NuGet packages they are doing it quite differently here are some examples from the extensions related packages:

  • Microsoft.Extensions.DependencyInjection.Abstractions only refers to netstandard2.0
  • Microsoft.Extensions.Logging refers to netcoreapp3.1 and netstandard2.0
  • Microsoft.Extensions.DependencyInjection refers to netcoreapp3.1, netstandard2.1 and netstandard2.0.
    • The netstandard2.0 uses the Microsoft.Bcl.AsyncInterfaces so this is a difference between that target and the others.
  • Microsoft.Extensions.Hosting.Abstractions refers to netcoreapp3.1 and netstandard2.0
    • Also here the netstandard2.0 uses the Microsoft.Bcl.AsyncInterfaces, but the difference is that in this package there is no netstandard2.1 reference which causes a library that references netstandard2.1 (that has support for async interfaces) to have a reference to this non-netstandard2.1 library?

So, why does all almost all new NuGet packages include the netcoreapp3.x target framework but don't include netstandard 2.1? I can see the reason of netstandard2.0, but not the reason for including netcoreapp3.x without or instead of netstandard2.1.

(The reason I write netcoreapp3.x instead of netcoreapp3.0 and/or netcoreapp3.1 is because this is done in both netcoreapp3.0 and netcoreapp3.1 versions of the NuGet packages).

1
Who's your audience? Do you reference other NuGet packages?madreflection
Not quite sure what you are referring to with audience here, but my package is intended to be used for all frameworks that at least supports .NET Standard 2.0 (Currently I don't plan to use any 2.1 features) and ultimately be available on NuGet.org.Rune G

1 Answers

0
votes

The nuget package target that you chose should be compatible with the target framework of your project.

An useful article that helps understand the difference between .NET Core and .NET Standard: Demystifying .NET Core and .NET Standard

Here is a table that shows what what .NET Core target supports what .NET Standard

enter image description here

Image reference

Here you can find more specific information about the changes that that .NET Core 3.1 has.

Keep in mind that you can also add several framework targets to your nuget package.