As we all knows .NET support side by side execution of multiple versions of component. In most cases, updating a component is simple.However, even in the .NET world, it is possible to break assembly binding when you update a component. One achieve that control is the publisher policy assembly.
What is a publisher policy assembly?
A publisher policy assembly is an assembly that configures the policy to be used when the .NET runtime binds to an assembly. The publisher policy assembly is installed into the GAC and is named using the following naming convention:
The major_ver and minor_ver refer to the major and minor version of the old version of the assembly. Therefore, if you are updating version 1.0 of Website.dll to version 2.0, and you want all existing applications to bind to the new version, the publisher policy assembly name would be:
After this publisher policy assembly is installed into the GAC, any application that references version 1.0 of Website.dll will bind to version 2.0 of Website.dll instead. At this point, you might be asking how the .NET runtime knows to bind to version 2.0 of Website.dll when it sees the publisher policy assembly in the GAC. The answer lies in the publisher policy file, an XML configuration file that is used to create the publisher policy assembly.
The publisher policy file contains the information necessary to redirect the binding from one version of an assembly to a new version. After you’ve created the publisher policy file, you use the .NET Assembly Linker utility (Al.exe) to create the publisher policy assembly.
Here is an example of a publisher policy file that redirects any reference to version 1.0 of Website.dll to version 2.0. The public key token can be obtained by looking at the properties of the assembly currently installed in the GAC.
<assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″> <dependentAssembly>
<assemblyIdentity name=”website” publicKeyToken=”18517ea673f8584b” culture=”neutral” />
<bindingRedirect oldVersion=”188.8.131.52″ newVersion=”184.108.40.206″/> </dependentAssembly>
The entire process
Scenario: You want to ensure that any ASP.NET application currently referencing version 1.0 of your server control uses version 2.0 instead after the updated version is installed. You don’t want anyone to have to modify configuration files for this to happen. You have wisely determined that a publisher policy assembly is the way to go.
This is how you should proceed.
1. Change the version and recompile. The first step is to create the new version of your component. After you’ve done that, you will need to modify the version number in the AssemblyInfo file for your component.
2.Create the publisher policy file.Create the publisher policy file for the assembly using the format shown above.
3.Use Assembly Linker (Al.exe) to create the publisher policy assembly. The Assembly Linker is included with the .NET Framework SDK. To create the publisher policy assembly that redirects a binding from version 1.0 of Website.dll to version 2.0 using a publisher policy file called website.config, run the following command:
al /link:website.config /out:policy.1.0.website.dll /keyfile:c:\keyfile.snk
This command will create a new assembly called policy.1.0.website.dll. This naming convention is important, as indicated in the “What Is a Publisher Policy Assembly?” section.
4.Install the publisher policy assembly into the Global Assembly Cache. The publisher policy assembly is installed into the GAC. It will be used by the .NET runtime when any application attempts to bind to version 1.0 of the Website.dll, and it will force the application to bind to the new version automatically.
5.Install the new version into the Global Assembly Cache. Install the new version of the component into the GAC. After the new version has been installed, the old version can be safely removed.
6.Restart Microsoft Internet Information Services (IIS). The final step is to restart IIS. This is necessary because of the way the .NET runtime binds to an assembly. If the .NET runtime has already bound to a specific assembly, it will reuse that binding. Therefore, for the binding redirect to the new assembly to work, you must restart the worker process.
After completing these steps, any application that was built with a reference to version 1.0 of Website.dll will automatically use version 2.0. Publisher policy assemblies offer a convenient way to ensure that developers have full control over assembly binding. As you’ve seen in this article, if your goal is to force existing applications to use a new version of your component, a publisher policy assembly provides you with the confidence that applications will always use the version you expect them to use without having to alter any configuration files or rely on manual changes by a server administrator.
You can find detail information at,