As mentioned in Gary's blog Dependent Assembly Binding Redirect (by version), it is possible to use a configuration file to change which version of an assembly to use. This can be very helpful in "tight versioning" scenarios (see blog Proxy Versioning Options for Project Templates ) where a specific version of a proxy is used. Here are some considerations for this:
In order to use a binding redirect the reference must have the SpecificVersion property set to True.
< Reference Include = "ShapeAppCSharpProxy, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b2943f7cfe902115, processorArchitecture=MSIL" >
< SpecificVersion > True</SpecificVersion >
</ Reference >
Generally the binding redirect can be specified in the application level configuration file AppName.exe.config (see Gary's blog ); however, there is a known bug with this for VSTA v 1 add-ins after Visual Studio 2008 SP1 is installed. The workaround is to specify the binding redirect in the machine level configuration file Machine.config. This file can be updated through the Microsoft .NET Framework 2.0 Configuration utility or programmatically with admin privileges- see code below.
private void EnsureMachineConfig()
//open the config file
Configuration MachineConfig = ConfigurationManager.OpenMachineConfiguration();
//Ge thte runtime section
ConfigurationSection runtimeSection = MachineConfig.Sections["runtime"]; //case sensitive
string content = runtimeSection.SectionInformation.GetRawXml();
//check if the proxy is already being re-directed
//add the entry
content = content.Replace(
"<assemblyIdentity name=\"ShapeAppCSharpProxy\" culture=\"Neutral\" publicKeyToken=\"b2943f7cfe902115\"/>" +
"<bindingRedirect oldVersion=\"188.8.131.52\" newVersion=\"184.108.40.206\"/>"+
//save the changes
For VSTA v 2 Visual Basic add-ins only one version of a proxy can be registered on a machine at any time due to the unique name requirment(see blog Proxy Assembly Registration- Unique Name Required ). For C# add-ins multiple versions of the same proxy can coexist.
Jul 27 2010, 11:21 AM