CodeSteps

Python, C, C++, C#, PowerShell, Android, Visual C++, Java ...

.Net – Assemblies – Create a Publisher Policy

As of now, we have created a hello shared assembly and installed it into GAC. We also created a new version of hello assembly and installed it into GAC. Now both these versions are inside GAC.

We have created a test application to access these assemblies. We have created the configuration file to instruct test application to use new hello assembly instead of the old one from GAC.

We have used application level configuration file to instruct our test application to take new hello assembly. Another configuration does exists, is global level configuration. These configurations exists in the run-time version folders. Application level configurations are applicable to particular application only. Global level configurations are applicable to all the applications those are built based on the particular run-time version.

Another configuration is publisher policy. These policies are stored in the GAC (Global Assembly Cache).

The benefit with publisher policy is, no need to create configuration file for each application. For eg: if your assembly is using multiple applications; you need to create application configuration file for each application to redirect to new assembly. Instead of that, if we create a publisher policy for the assembly; all applications will redirect to the new assembly.

You can also override publisher policy by creating application configuration file for your application.

To set up publisher policies:

  • Create a publisher policy configuration file. It is in XML format.
  • Once XML file is created, attach it to the assembly.
  • If the assembly is not install into GAC; it should be  into GAC.

Remember that publisher policies are apply to shared assemblies only.

Create a publisher policy for assembly

Lets create a publisher policy for our assembly.

We can use the application configuration file for our publisher policy. In our previous article, we have created testapp.exe.config file. We will use the same here. Rename the file to hello.config.

Now we need to create a publisher policy assembly. To create this assembly, we use; hello.config file and hello.key file. hello.key file must be the same as we used to create our hello assembly. And the generated assembly name must be like below:

policy.<major and minor numbers of the assembly we want to re-direct>.<assembly-name>

In our case, assembly-name is hello.exe, major and minor version numbers are 0 and 0 respectively. So, publisher policy assembly name will be policy.0.0.hello.exe.

Let’s generate this publisher policy assembly. Remember that we should add hello.config and hello.key files.

al /linkresource:hello.config /keyfile:hello.key /out:policy.0.0.hello.exe

The above command will generate publisher policy assembly. Now we need to install this assembly into GAC.

gacutil /i policy.0.0.hello.exe

This will install our publisher policy into GAC.

Now run our test application testapp.exe and observe that it will display “Hello, Universe!” message; which means it is taking the new hello assembly.

**

.Net – Assemblies – Create a Publisher Policy

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top