Share via


Some clarity on policy file creation in .NET

First of all, How to create policy files:

Take example of dll abc.dll.

Policy file should be created with name: policy.major.minor.assemblyname.dll

 

(Here major and minor are Old dll’s major and minor version, Assembly name is dll name)

 

So for abc.dll with major and minor version 1.0, you have to create policy file ‘policy.1.0.abc.dll’ and put in GAC.

For abc.dll with major and minor version 1.2, you have to create policy file ‘policy.1.2.abc.dll’ and put in GAC.

 

Command for creating policy file: al /link:abc.dll.config /out: policy.1.0.abc.dll /keyfile:abc.snk /v:1.0.0.0

                                                             al /link:abc.dll.config /out: policy.1.2.abc.dll /keyfile:abc.snk /v:1.2.0.0

Now here is some more clarity:

https://msdn.microsoft.com/en-us/library/7wd6ex19(VS.80).aspx

This msdn article says:

(a) If we want to redirect from version 1.1.0.0-1.2.0.0 to version 2.0.0.0, according to section "Redirecting Assembly Versions Using Publisher Policy" in above msdn article, they should be in different policy file, according to the "Redirecting Assembly Versions" section, they can go into one policy file.

(b) What’s the name of the Policy DLL should be? In MSDN it said the name is “policy.majorNumber.minorNumber.mainAssemblyName.dll” – then it should be “policy.1.1.mainAssemblyName.dll” or “policy.1.2.mainAssemblyName.dll”?

 

The above link is an article about redirecting versions in general, rather than specific to publisher policy. We use the same syntax for both config files, as well as publisher policy files. So, when used in a configuration file, the syntax allows for ranges of major/minor “oldVersions”, but the publisher policy infrastructure requires separate files for each major/minor version.

 

Each major.minor version of an assembly has its own publisher policy file. For example, redirections from version 1.1.2.222 to 1.1.3.000 and from version 1.1.2.321 to version 1.1.3.000 both go into the same file. However, a redirection from version 2.0.0.999 to version 3.0.0.000 goes into a different file.

The above sentence is from the “Redirecting Assembly Versions Using Publisher Policy” section, and is true for publisher policy.

 

To redirect one version to another, use the <BindingRedirect> element. The oldVersion attribute can specify either a single version, or a range of versions. For example, <bindingRedirect oldVersion="1.1.0.0-1.2.0.0" newVersion="2.0.0.0"/> specifies that the runtime should use version 2.0.0.0 instead of the assembly versions between 1.1.0.0 and 1.2.0.0.

The above sentence is from the “Specifying Assembly Binding in Configuration Files” section and is true for configuration files (machine.config/app.config/web.config/host.config etc.)

 

Hope it clears the doubt and give detail about using policy file and configuration for assembly version redirection.

Disclaimer: This is a personal weblog. The opinions expressed here represent my own and not those of my employer.