Nuget multi-targeting for direct or indirect dependencies

18 views Asked by At

I have a dependency (dep) graph for my app and nugets as below.

app (net8.0)
    -> nugetA (net6.0)             <--- target net8.0 as well?!
        -> nugetB (net8.0, net6.0)

What target framework of nugetB will app, which is on net8.0, use? net8.0 or net6.0?

A concrete example is,

app (net8.0)
    -> nugetA (net6.0)             <--- target net8.0 as well?!
        -> System.Text.Json (net8.0, net6.0)

As per MS recommendations, nugetA should also target net8.0 in order to benefit from the framework-specific code blocks as nugetB does that.

✔️ CONSIDER multi-targeting even if your source code is the same for all targets, when your project has any library or package dependencies.

Your project's dependent packages, either direct or downstream, might use the same code APIs while wrapped inside different versions of the dependent assembly per target framework. Adding specific targets ensures that your consumers do not need to add or update their assembly binding redirects.

ref: https://learn.microsoft.com/en-us/dotnet/standard/library-guidance/cross-platform-targeting#multi-targeting

However, this creates a maintenance nightmare if there are a lot of nugets to maintain. Ideally, I'd like to avoid this.

Not to mention that if nugetB changes to add framework-specific code blocks in the future (when say net9.0+ come out), nugetA should also do so to benefit from it.

0

There are 0 answers