1

I have a GitHub project (Test Automation Essentials) which references some Visual Studio specific assemblies (Microsoft.VisualStudio.TestTools.UITest.Extension which is part of CodedUI; but that's not significant for the question). This project is published as a NuGet package containing my class library.

I want my project to support different versions of Visual Studio, and all in all, this assembly does not have any noticeable differences between the versions of Visual Studio, so I don't anticipate any compatibility issues (it should be backward compatible anyway).

However, if I compile my project in one version of Visual Studio (e.g. 2015), when I try to reference the NuGet package from a project in a newer version of Visual Studio (e.g. 2017), when the hosting project runs I get the following exception:

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.TestTools.UITest.Extension, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file 

Note: my library references this assembly with Specific Version=False.

I found I can work around this issue by adding the following element to the app.config of the application:

  <dependentAssembly>
    <assemblyIdentity name="Microsoft.VisualStudio.TestTools.UITest.Extension" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="12.0.0.0-15.0.0.0"  newVersion="15.0.0.0"/>
  </dependentAssembly>

Note: In this particular case the executable is typically QTAgent32_40.exe which is itself part of Visual Studio, so I had to add the element to QTAgent32_40.exe.config and not actually to the project's app.config file. QTAgent32_40.exe.config already has many similar dependentAssembly elements, but for some reason not for this specific assembly.

The question:

I don't want my clients to add this setting themselves. I'd be glad if I could have such a setting specific for my class library, so that anyone who references my library automatically gets this Assembly Redirect setting. However, I didn't find a way to do that...

Does anyone knows how can I do it?

Arnon Axelrod
  • 1,444
  • 2
  • 13
  • 21

1 Answers1

0

The only way to do this is to create a Nuget package for each specific version of Visual Studio.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • Is there an easy way to do it without duplicating the csproj for each version? – Arnon Axelrod Apr 27 '18 at 12:04
  • You could have multiple build configs of the same project. – jessehouwing Apr 27 '18 at 15:28
  • You can write selective references in msbuild using the choose/when construct and when you use visual studio 15.6+ you can also include selective packageReference items to reference specific nuget packages and/or package versions. You can find an example implemented here https://github.com/tfsaggregator/tfsaggregator – jessehouwing Apr 27 '18 at 18:22