1

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?

Athari
  • 33,702
  • 16
  • 105
  • 146
noelep
  • 55
  • 4
  • 1
    This is because there are some System.XXX.dll are found in 4.6.1 but not in 2.0, so naturally, it have to be copied together or it will be missing those files. One example I can think of is the System.IO.Compression Namespace 2.0 https://msdn.microsoft.com/en-us/library/system.io.compression(v=vs.80).aspx 4.6.1 https://msdn.microsoft.com/en-us/library/system.io.compression(v=vs.110).aspx Notice that 4.6.1 has many more things than 2.0, and if you were to use a 4.6.1 item in the 2.0 project, it will not work, the only way is to have the 2.0 reference the 4.6.1 dll – Allanckw Nov 08 '17 at 16:34
  • I am talking about the reverse of this situation - the System.*.dll are being output with the net461 build...even though all (most?) of those APIs are built into the framework. Jacek's answer below regarding shims explains it. – noelep Nov 08 '17 at 20:08
  • related: https://stackoverflow.com/questions/49417054/how-do-i-prevent-net-4-7-1-libraries-from-copying-the-facade-dlls-to-the-bin-fo – CAD bloke Jan 08 '20 at 22:20

1 Answers1

3

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.

Jacek Blaszczynski
  • 3,183
  • 14
  • 25
  • actually the libraries are added if any dll in the dependency closure references a .net standard assembly. So if you create a netstandard 2.0 assembly and add it as a reference to a classic project, it will add the shims. This is done by build logic shipped in VS 2017 and the CLI which is also available as extension for VS 2015 – Martin Ullrich Nov 08 '17 at 17:58
  • The link from Jacek is exactly it - not sure how I didn't come across it when searching beforehand. – noelep Nov 08 '17 at 20:03
  • Still trying to wrap my head around exactly what is going on under the covers here...I (apparently naively!) thought it was doing a complete standalone build against net461 – noelep Nov 08 '17 at 20:11
  • @noelep I'm having the same problem and wanted to know that too. Did you eventually resolve it? – Zimano Sep 03 '19 at 19:17