How to make bindingRedirect dll in Vsix extension?

I have an extension for VS that should use the Gmail api to send emails to specific users in my company. During development, I get into a general problem with the version of System.Net.Http.Primitives , which somehow got confused in the Google API.

a common solution for this is to put bindingRedirect in app.config to redirect calls to a new updated version of the library. As below:

 <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0"/> </dependentAssembly> </assemblyBinding> </runtime> 

However, this does not seem to work if my output is a Vsix package. The generated Vsix does not even have app.config.

I know a solution that adds the bindingRedirect file to machine.config , but my extensions are used by some other people, and I would rather not force them to put files in their machine configuration files.

Is there any other solution for this?

+5
source share
2 answers

Technically, app.config refers to a process (.exe), not a dll. For Visual Studio, this is the devenv.exe.config file located in the C: \ Program Files (x86) \ Microsoft Visual Studio <version & \ Common7 \ IDE folder.

But to modify this file, the extension must be installed with administrator rights (i.e. .msi or a similar installation technology). And I do not think that it is a good idea to modify this file, as this will affect other extensions.

One approach you can try is to redirect the binding using code, somehow causing the assembly permission to fail by subscribing to AppDomain.AssemblyResolveEvent to be able to provide the exact assembly you want. See: http://blog.slaks.net/2013-12-25/redirecting-assembly-loads-at-runtime/

+2
source

This was answered over a year ago, but I found a better way to do this using ProvideBindingRedirectionAttribute . This will add the binding forwarding to devenv and also determine the correct version. Detailed information can be found here , but the relevant part is here:

Using the ProvideBindingRedirection attribute, you can specify the binding redirection to install the update on the extensible component. When you submit an extensible Visual Studio component, this attribute prevents users of the component from installing the old version of the dependent component. If you use the ProvideBindingRedirection attribute, you do not need to manually update the exe.config file to redirect users of the old version of the assembly to the new version. Adding the ProvideBindingRedirection assembly attribute is an easy way to add a binding redirect entry to the pkgdef file. The pkgdef file is used to install the extension.

The following example shows the 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")]

+14
source

All Articles