Here's a situation I've found myself in quite a bit lately. Do this:
- In VS 2019 16.4.5, create a new C# console application targetting .net 4.7.1
- Add a reference to System.IO.Compression
Add this line to Main() (it will crash if you actually try to run, so don't):
var a = new System.IO.Compression.ZipArchive(System.IO.Stream.Null);
Compile
- Examine the output exe's metadata. It will contain a reference to System.IO.Compression version 4.0, which is presumably the version included with .net 4.7.1.
Now, do this:
- In VS 2019 16.4.5, create a new C# console application targetting .net 4.7.1
- Install the nuget package System.Threading.Tasks.Extensions version 4.5.3 (latest version at the time of posting; nothing special about this package, just using it as an example)
Add this line to Main() (it will crash if you actually try to run, so don't):
var a = new System.IO.Compression.ZipArchive(System.IO.Stream.Null);
Compile
- Navigate to the output directory. msbuild will have placed System.IO.Compression.dll there, but it's version 4.2. This appears to be because System.Threading.Tasks.Extensions has a transitive dependency on System.IO.Compression 4.2. The metadata for the compiled exe will show that it also references version 4.2 now instead of 4.0.
That's all well and good until you try to deploy the application to another machine and it fails at runtime because only version 4.0 of System.IO.Compression is included with the 4.7.1 redistributable. So what is the solution to this? Do I:
- Deploy System.IO.Compression 4.2 with my application and have the installer copy it to the install directory alongside the exe?
- Mess around with binding redirects?
- Figure out what redistributable does include version 4.2, and include both that one and the 4.7.1 framework redistributable in my installer?
- Something else entirely?