Multi-target netstandard1.0 and netstandard2.0 side-by-side?

Viewed 645

When I create a multi-target .NET csproj which targets netstandard1.2, netstandard2.0 and net45, do I have to include both of the netstandard monikers in the section of the .csproj or is it enough to just mention netstandard1.2 (the lower netstandard version)?

Proposal A:

<TargetFrameworks>netstandard1.2;net45</TargetFrameworks>

Proposal B:

<TargetFrameworks>netstandard1.2;netstandard2.0;net45</TargetFrameworks>

2 Answers

Yes, there is a difference between the behavior of netstandard1.x and netstandard2.x.

From Microsoft docs:

✔️ DO include a netstandard2.0 target if you require a netstandard1.x target.

All platforms supporting .NET Standard 2.0 will use the netstandard2.0 target and benefit from having a smaller package graph while older platforms will still work and fall back to using the netstandard1.x target.

And one paragraph above explains the difference:

.NET Standard 1.x is distributed as a granular set of NuGet packages, which creates a large package dependency graph and results in developers downloading a lot of packages when building. Modern .NET platforms, including .NET Framework 4.6.1, UWP and Xamarin, all support .NET Standard 2.0. You should only target .NET Standard 1.x if you specifically need to target an older platform.

netstandard1.x supports 2 frameworks by using nugets, which causes the import of many packages.

When I check the dependencies of both NuGet packages (1) with <TargetFrameworks>netstandard1.2;net45</TargetFrameworks> and (2) with <TargetFrameworks>netstandard1.2;netstandard2.0;net45</TargetFrameworks> I see that netstandard1.2 includes NETStandard.Library (>=1.6.1) which is probably the "depedency graph" which is described in @Baruch's answer.

ObjectDumper.Net dependencies (1)

ObjectDumper.NET with netstandard1.2 only

ObjectDumper.Net dependencies (2)

ObjectDumper.NET with netstandard1.2 and netstandard2.0

To my knowledge, I can use <TargetFrameworks>netstandard1.2;net45</TargetFrameworks> if I want to support both, netstandard1.2 and netstandard2.0. A netstandard2.0 project which consumes a netstandard1.2 NuGet package references NETStandard.Library 2.0.3 (which fulfills the minimum requirement >=1.6.1). So, no unnecessary NuGet packages will be installed.

Related