GAC Assembly redirection for several .dlls

1.3k views Asked by At

I'm trying to redirect a specific .dll, let's call it MyAssembly.dll. This assembly has two versions:

MyAssembly.dll version 1.0.0.0

and

MyAssembly.dll version 1.1.0.0

I want these two assemblies to redirect to its third version: 1.2.0.0. For that purpose, I wrote this .config file to build the Publisher Policy to be applied on GAC:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
            <assemblyIdentity name="MyAssembly" publicKeyToken="myPublicKeyToken" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.2.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

With this, I create the appropiate .config file to generate the policy. But my problem comes when I want to create the Policy.

Note before next step: an assembly versioning works like this:

<major version>.<minor version>.<build number>.<revision>

First time I wanted to create a Policy, I realized that, if the assembly version I want to redirect is: 1.0.0.0 I had to create a policy that matched like this:

Policy.<majorversion>.<minorversion>.<AssemblyName>.dll

With this, I'm able to redirect any MyAssembly.dll from 1.0.* to up, to version 1.1.

But, how can I generate that policy if I want to redirect more than one assembly, like I explained above? How should my policy look like?

If I have two assemblies:

1.0.0.0 - 1.1.0.0

How do I build the PublisherPolicy?

1

There are 1 answers

1
Sonhja On BEST ANSWER

Due to this article, I had to create one Policy for each combination of MajorVersion.MinorVersion of my assembly. So I had to create two policies:

  • One to be able to redirect from 1.0.0.0 to 1.2.0.0
  • And another one to redirect from 1.1.0.0 to 1.2.0.0

This solution works, but if anyone knows a more efficient way to do this, I will really appreciate it.