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?