Thursday, August 11, 2011

.Net Assembly Redirection

Sometimes, we need redirect an assembly to a different version, we can do it like this:

<?xml version="1.0" encoding="utf-8" ?><configuration>    <runtime>        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">            <probing privatePath="libs"/>            <dependentAssembly>                <assemblyIdentity name="MathLibrary"                    publicKeyToken="8210BDCE54DAB3C2"/>                <bindingRedirect oldVersion="1.1.1.1"                    newVersion="1.1.2.2"/>            </dependentAssembly>        </assemblyBinding>    </runtime></configuration>

 

In element “probing, “privatePath” is additional seraching path for assemblies.

In element “assemblyIdentity“, “name” is the assmebly you want to redirect, “publicKeyToken” is its public key. So the assembly must be strong-named to make a redirection.

After set the assembly, you can make your redirection. In element “bindingRedirect“, use “oldVersion” & “newVersion” to redirect it.

 

No comments:

Post a Comment