Search code examples
c#package.net-standard.net-standard-2.0.net-4.6.1

Large number of assemblies in net461 output folder when building .NET Framework/.NET Standard multitargeting project


I have an new SDK-style csproj that targets multiple frameworks:

<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>

The dependencies node in VS lists '.NETFramework 4.6.1' and '.NETStandard 2.0' as expected - and the NETStandard folder has 'NETStandardLibrary' as an SDK dependency.

My understanding of the multiple TFMs was to cross compile the class library for use as a Full Framework dll, or a netstandard dll. However, in the net461 output folder I see 100+ System.xxx.dll, including netstandard.dll.

Why are all these assemblies in the output? Or am I misunderstanding the concept of multiple target frameworks?


Solution

  • The problem is described in detail in several issues in DotNet Standard repo. The short explanation is:

    The reason is that net471 is the first .NET Framework to actually contain netstandard20 APIs- the others use shims

    It means that every time .NETStandard nuget package is referenced it will pull entire .NETStandard bunch of assemblies if version of .NET Framework is lower than v4.7.1.