3

I have a project where I would want to use some specific version of a dll.

The GAC contains couple of versions of that dll (new & old), I would want to use the old when running the program.

Issue is that the newest dll is always picked-up from the GAC.

Would you know if there is a way to either:

  • Force the usage the dll that is in the run folder (the one I'm referencing in my solution, working fine in debug).
  • Force the usage of the old version of the dll from the GAC.

Thank you!

Aage
  • 5,932
  • 2
  • 32
  • 57
goul
  • 813
  • 1
  • 13
  • 32

3 Answers3

1

You can use a binding redirect in your app.config or web.config in the runtime node:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
  </appSettings>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Make sure you have the correct publicKeyToken and know which versions you want to redirect to what version.

(You can check a publicKeyToken of a DLL like this with this info.)

MSDN Documentation

You can also generate these for an entire solution using the Package Manager Console

Get-Project -All | Add-BindingRedirect

This will update all app.config files and add the binding redirect.

Aage
  • 5,932
  • 2
  • 32
  • 57
0

When you have added the library to your project and you collapse the 'References'-node of the project tree, you'll see the added library. When you select it and click the 'Properties'-node of the context menu, you can specify if a specific version of the library should be used and which version to use. Simply set 'Specific Version' to true and specify the Version number. Then you don't have to cope with the question where the version you want is loaded from.

Matten
  • 17,365
  • 2
  • 42
  • 64
  • 1
    Hi Matten. Thanks for your answer, but given what I can read here and my tests, this seems to be only for compile time, not run time: http://stackoverflow.com/questions/1232842/use-of-specific-version-reference-in-visual-studio-2008 – goul Aug 05 '14 at 05:41
  • Yes, this is only at compile time. – VansFannel Jan 26 '16 at 15:56
0

Have you try to "Redirecting Assembly Versions" in your app.config? http://msdn.microsoft.com/en-us/library/7wd6ex19(v=vs.110).aspx

Jun Guo
  • 484
  • 1
  • 3
  • 14