开发者

nUnit - ignore GAC copy of a DLL

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 versio开发者_运维百科n that changes as per KB 556041 - How to use Assembly Version and Assembly File Version


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!


What I tend to do in this situation is to NOT sign the assembly when unit testing until I am ready to deploy it. It is a one step process where you go to the project properties and clear the Sign the assembly setting. When you recompile, next time you run the tests, NUnit will pick it up from a local bin folder, since unsigned assemblies cannot be deployed to GAC. What I found is that even if you have a version of the assembly in GAC already, it will still take the unsigned version if you reference the assembly under test by the project. When you're done with the tests, you turn the setting back on and deploy.

Not ideal as you now have that extra step to go through, but as close as I could get without doing a lot of work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜