views:

467

answers:

2

Assemblies A and B are privately deployed and strongly named. Assembly A contains references to Assembly B. There are two versions of Assembly B: B1 and B2. I want to be able to indicate for Assembly A that it may bind to either B1 or B2 -- ideally, by incorporating this information into the assembly itself. What are my options?

I'm somewhat familiar with versioning policy and the way it applies to the GAC, but I don't want to be dependent on these assemblies being in the GAC.

+1  A: 

You can set version policy in your app.config file. Alternatively you can manually load these assemblies with a call to Assembly.LoadFrom(..) when this is done assembly version is not considered.

Aaron Fischer
+2  A: 

There are several places you can indicate to the .Net Framework that a specific version of a strongly typed library should be preferred over another. These are:

  • Publisher Policy file
  • machine.config file
  • app.config file

All these methods utilise the "<bindingRedirect>" element which can instruct the .Net Framework to bind a version or range of versions of an assembly to a specific version.

Here is a short example of the tag in use to bind all versions of an assembly up until version 2.0 to version 2.5:

<assemblyBinding>
    <dependantAssembly>
        <assemblyIdentity name="foo" publicKeyToken="00000000000" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0 - 2.0.0.0" newVersion="2.5.0.0" />
    </dependantAssembly>
</assemblyBinding>

There are lots of details so it's best if you read about Redirecting Assembly Versions on MSDN to decide which method is best for your case.

Aydsman