How to do dll bindingRedirect in a Vsix extension?

This was answered over a year ago, but I found a better way to do it by using ProvideBindingRedirectionAttribute. This will add the binding redirects to devenv, and also determine the correct version. Details can be found here, but the relevant part here:

By using the ProvideBindingRedirection attribute, you can specify binding redirection for the installation of an upgrade to an extensible component. When you ship an extensible Visual Studio component, this attribute prevents users of the component from having to install an old version of a dependent component. If you use the ProvideBindingRedirection attribute, you don't need to manually update the exe.config file to redirect users of the old assembly version to the new version. Adding a ProvideBindingRedirection assembly attribute is an easy way to add a binding redirection entry to the pkgdef file. The pkgdef file is used to install the extension.

The following example shows a ProvideBindingRedirection entry in the AssemblyInfo.cs or AssemblyInfo.vb file:

[assembly: ProvideBindingRedirection(AssemblyName = "ClassLibrary1", NewVersion = "3.0.0.0", OldVersionLowerBound = "1.0.0.0", OldVersionUpperBound = "2.0.0.0")]


Technically, the app.config belongs to the process (.exe), not to the dlls. For Visual Studio, it is the devenv.exe.config file located at C:\Program Files (x86)\Microsoft Visual Studio <version>\Common7\IDE.

But to modify that file your extension should be installed with admin rights (that is, .msi or similar installer technology). And I don't think it's a good idea to modify that file since it would affect other extensions.

One approach that you can try is to redirect binding by code somehow forcing an assembly resolution failure, subscribing to the AppDomain.AssemblyResolveEvent, to get a chance of providing the exact assembly that you want. See: http://blog.slaks.net/2013-12-25/redirecting-assembly-loads-at-runtime/