Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nUnit - ignore GAC copy of a DLL

Tags:

.net

nunit

gac

I am using a nUnit to, well, unit test an assembly.

The assembly is in my project output dir (\bin\debug) and is loaded into nUnit (Assemblies > Add Assembly) from this location.

However an older version is also in the GAC and nUnit is picking this one up instead.

I can of course remove the old version and re-install to the GAC upon build but this takes some time - any way to force nUnit (or more likely the .NET framework) to pick up the version from the bin\debug dir?

EDIT

The AssemblyVersion (and hence strong name) of both versions are fixed - its only the file version that changes as per KB 556041 - How to use Assembly Version and Assembly File Version

like image 282
Ryan Avatar asked Sep 20 '10 11:09

Ryan


1 Answers

You could try to make a <bindingRedirect> in your .config file to redirect to your local assembly and to not use the one installed in the GAC.

When you build a .NET Framework application against a strong-named assembly, the application uses that version of the assembly at run time by default, even if a new version is available. However, you can configure the application to run against a newer version of the assembly

...

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity
            name="myAssembly"
            publicKeyToken="32ab4ba45e0a69a1"
            culture="neutral" />
        <bindingRedirect
            oldVersion="1.0.0.0"
            newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

This might also be interesting for you:

  • MSDN: How the Runtime Locates Assemblies

Hope that helps!

like image 83
Martin Buberl Avatar answered Oct 03 '22 05:10

Martin Buberl