Search code examples
c#assembly-binding-redirect

Compiling against a higher version of assemblies but binding redirect to lower versions in app.config


I am compiling my DLLs against a third party strong named assembly (thirdparty.dll) with version 2.0.0.0.

But, when I ship my DLLs and exes to client's machine, I want to ship thirdparty.dll version 1.0.0.0 ( don't ask why, I have a reason to do that).

Is this possible? My understanding is that yes, as long as I specify the dependentAssembly tag as such

  <dependentAssembly>
    <assemblyIdentity name="thirdparty" culture="neutral" publicKeyToken="3d67ed1f87d44c89"/>
    <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="1.0.0.0"/>
  </dependentAssembly>

Because for newVersion ,

This value can specify an earlier version than oldVersion.

The code will work, barring any compilation issues that arise when/if I compile the code against thirdparty.dll version 1.0.0.0.

Is my understanding correct?


Solution

  • To answer my own question: YES, it is correct.

    EG:

     <dependentAssembly>
        <assemblyIdentity name="thirdparty" culture="neutral" publicKeyToken="3d67ed1f87d44c89"/>
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="1.0.0.0"/>
      </dependentAssembly>
    

    will work ( all the versions between 0.0.0.0 and 2.0.0.0 will be redirected to 1.0.0.0), and so will:

     <dependentAssembly>
        <assemblyIdentity name="thirdparty" culture="neutral" publicKeyToken="3d67ed1f87d44c89"/>
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="4.0.0.0"/>
      </dependentAssembly>
    

    all the versions between 0.0.0.0 and 2.0.0.0 will be redirected to 4.0.0.0