2

I noticed that after referencing a .net standard lib (1.4) from my .net full project (4.6.1) That my output folder is full of System.*.dll assemblies.

Does this mean that if I target the full framework but reference a .net standard lib I have to ship with the .net standard version(s) of all the System libraries that it uses?

Athari
  • 33,702
  • 16
  • 105
  • 146
trampster
  • 8,598
  • 4
  • 37
  • 52
  • random question: did you try nuking the files after build to see whether it still works? my *guess* would be that it is fine to delete them as long as you don't expect anything to work... (i.e. don't do that) – Marc Gravell Mar 26 '17 at 21:48
  • 1
    They do seem to be required to make it work, It's just not something that we expected. PCL's don't behave this way. This is bloating out our deployment and making us rethink going to .net standard. I expected that .net standard libs would use the system assemblies from 4.6.1. Seeing as microsoft is claiming it is compatible. – trampster Mar 26 '17 at 21:52
  • well, it *is* compatible... you're in "full", and you're using the lib... – Marc Gravell Mar 26 '17 at 21:54
  • 1
    Not really, you are not actually using the BCL from 4.6.1 only the runtime. That's a very strange definition of compatible. It only works if you replace half the system is not really compatible in my opinion. – trampster Mar 26 '17 at 21:56
  • I was hoping I had done something wrong in the way I was referencing them. – trampster Mar 26 '17 at 22:05

1 Answers1

1

Normally when you make a .NET standard library you want to do Multi-targeting. In your .csproj file you would change your

<TargetFramework>netstandard1.4</TargetFramework>

to

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

Notice the adding of the s to the tag.

Once you do that, and you generate the NuGet package for the library the library will support both .net 4.5 and netstandard directly.

For an example, here is from Json.NET's csproj file.

<TargetFrameworks Condition="'$(DotnetOnly)'==''">net45;net40;net35;net20;netstandard1.0;netstandard1.3;portable-net45+win8+wpa81+wp8</TargetFrameworks>

So it will generate DLLs for .NET 4.5, .NET 4.0, .NET 3.5, .NET 2.0, netstandard 1.0, netstandard 1.3 and a PCL library that targets net45, win8, wpa81, and wp8, All of those dll's will get packaged in to the NuGet package and only the closest match gets used when you reference the package.

Doc Brown
  • 19,739
  • 7
  • 52
  • 88
Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431