Creating a Publisher Policy File

Vendors of assemblies can state that applications should use a newer version of an assembly by including a publisher policy file with the upgraded assembly. The publisher policy file specifies assembly redirection and code base settings, and uses the same format as an application configuration file. The publisher policy file is compiled into an assembly and placed in the global assembly cache.

There are three steps involved in creating a publisher policy:

  1. Create a publisher policy file.
  2. Create a publisher policy assembly.
  3. Add the publisher policy assembly to the global assembly cache.

Creating the Publisher Policy File

The schema for publisher policy is described in Redirecting Assembly Versions.

The following example shows a publisher policy file that redirects one version of myAssembly to another.

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
       <dependentAssembly>
         <assemblyIdentity name="myAssembly"
                           publicKeyToken="32ab4ba45e0a69a1"
                           culture="en-us" />
         <!-- Redirecting to version 2.0.0.0 of the assembly. -->
         <bindingRedirect oldVersion="1.0.0.0"
                          newVersion="2.0.0.0"/>
       </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

To learn how to specify a code base, see Specifying an Assembly's Location.

Creating the Publisher Policy Assembly

Use the Assembly Linker (Al.exe) to create the publisher policy assembly.

To create a publisher policy assembly

  • Type the following command at the command prompt:

    **al /link:**publisherPolicyFile **/out:**publisherPolicyAssemblyFile **/keyfile:**keyPairFile

    In this command:

    • The publisherPolicyFile argument is the name of the publisher policy file.

    • The publisherPolicyAssemblyFile argument is the name of the publisher policy assembly that results from this command. The assembly file name must follow the format:

      policy.majorNumber.minorNumber.mainAssemblyName.dll

    • The keyPairFile argument is the name of the file containing the key pair. You must sign the assembly and publisher policy assembly with the same key pair.

    The following command creates a publisher policy assembly called policy.1.0.myAssembly from a publisher policy file called pub.config, and assigns a strong name to the assembly using the key pair in the sgKey.snk file.

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

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
    

See Also

Programming With Assemblies | How the Runtime Locates Assemblies | Configuration Files | Configuring Applications | Runtime Settings Schema | Configuration File Schema