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:126.96.36.199
al /link:abc.dll.config /out: policy.1.2.abc.dll /keyfile:abc.snk /v:188.8.131.52
Now here is some more clarity:
This msdn article says:
(a) If we want to redirect from version 184.108.40.206-220.127.116.11 to version 18.104.22.168, 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 22.214.171.124 to 1.1.3.000 and from version 126.96.36.1991 to version 1.1.3.000 both go into the same file. However, a redirection from version 188.8.131.529 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="184.108.40.206-220.127.116.11" newVersion="18.104.22.168"/> specifies that the runtime should use version 22.214.171.124 instead of the assembly versions between 126.96.36.199 and 188.8.131.52.
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.