nUnit - 忽略 DLL 的 GAC 副本
我正在使用 nUnit 对程序集进行单元测试。
该程序集位于我的项目输出目录 (\bin\debug) 中,并从此位置加载到 nUnit(程序集 > 添加程序集)中。
然而,GAC 中也有一个旧版本,nUnit 正在选择这个版本。
我当然可以删除旧版本并在构建时重新安装到 GAC,但这需要一些时间 - 有什么方法可以强制 nUnit(或更可能是 .NET 框架)从 bin\debug 目录中获取版本?
编辑
两个版本的 AssemblyVersion (以及因此的强名称)都是固定的 - 它只是根据 更改的文件版本KB 556041 - 如何使用程序集版本和程序集文件版本
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试制作
在您的 .config 文件中重定向到本地程序集,并且不使用 GAC 中安装的程序集。您可能也会对此感兴趣:
希望有帮助!
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.This might also be interesting for you:
Hope that helps!
在这种情况下,我倾向于做的是在单元测试时不签署程序集,直到我准备好部署它。这是一个一步过程,您可以转到项目属性并清除“签署程序集”设置。当您重新编译时,下次运行测试时,NUnit 将从本地 bin 文件夹中选取它,因为未签名的程序集无法部署到 GAC。我发现,即使您已经在 GAC 中拥有该程序集的版本,如果您引用项目正在测试的程序集,它仍然会采用未签名的版本。
完成测试后,您可以重新打开设置并进行部署。
这并不理想,因为您现在需要执行额外的步骤,但我可以在不做大量工作的情况下尽可能接近。
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.