Configuring Publisher Policy File

Versioning in the Microsoft .NET Framework is managed at the assembly level and is only used when locating strong-named assemblies.

By default, the common language runtime loads the assembly whose entire version number matches the version number in the calling assembly's metadata.

However, the runtime can be instructed to load a different version of an assembly by using version policy.

You can control how the common language runtime locates an assembly by providing it with a set of binding rules.

As the vendor of the referenced assembly, you can create a publisher policy configuration file and use the <bindingRedirect> and <codeBase> elements to force the application to use the latest version of your assembly.

The document describes the steps that are required to create a publisher policy file.

The publisher policy configuration file is used to force all the applications to use a newer version of the assembly, there will two assemblies installed by doing this.

The first assembly, publisher policy assembly contains only the publisher policy configuration file and must be installed in the GAC, because versioning changes effect all applications that use the assembly. The second assembly contains the code that is referenced by other assemblies.

Steps in Creating Publisher Policy Assembly

Creating the Publisher Policy File:

The following is an example of a publisher policy configuration file:

<configuration>
<runtime>
<
assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<
dependentAssembly>
<
assemblyIdentity name="myasm"
publicKeyToken="e9b4c4996039ede8"
culture="en-US"/>
<
bindingRedirect oldVersion="1.0.0.0 "
newVersion="2.0.0.0"/>
<
codeBase version="2.0.0.0"
href="http://www.mysite.com/my.dll"/>
</
dependentAssembly>
</
assemblyBinding>
</
runtime>
</
configuration>

The information for each assembly that requires redirection is placed inside the <dependentAssembly> element of the publisher policy configuration file.

The <bindingRedirect> element redirects the reference to a different version of a strong-named assembly by overriding the version in the original reference with a reference to the newer version. In the previous example the assembly reference to version 1.0.0.0 is redirected to version 2.0.0.0.

Compiling the Publisher Policy Assembly

The Assembly Generation tool (Al.exe) is used to compile a publisher policy assembly. The following command demonstrates how the Assembly Generation tool is used to build a publisher policy assembly:

al /link:myAssembly.dll.config /out:policy.1.0.myAssembly.dll
/keyfile:sgKey.snk

The output file name must be in the following format:

policy.< major >.< minor >.< assembly name >.< assembly extension

Adding the Publisher Policy Assembly to the Global Assembly Cache

Use the Global Assembly Cache tool (Gacutil.exe) to add the publisher policy assembly to the global assembly cache.

To add the publisher policy assembly to the global assembly cache

  • Type the following command at the command prompt:

    gacutil /i publisherPolicyAssemblyFile
  • The following command adds policy.1.0.myAssembly.dll to the global assembly cache.

    gacutil /i policy.1.0.myassembly.dll

Up Next
    Ebook Download
    View all
    Learn
    View all