nUnit - 忽略 DLL 的 GAC 副本

发布于 2024-09-24 03:26:08 字数 418 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痴情 2024-10-01 03:26:08

您可以尝试制作 在您的 .config 文件中重定向到本地程序集,并且不使用 GAC 中安装的程序集。

当您针对强名称程序集构建 .NET Framework 应用程序时,即使有新版本可用,该应用程序也会默认在运行时使用该版本的程序集。但是,您可以将应用程序配置为针对较新版本的程序集运行

...

<前><代码><配置>;
<运行时>
< assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<依赖程序集>
<程序集标识
名称=“我的程序集”
publicKeyToken =“32ab4ba45e0a69a1”
文化=“中立”/>
<绑定重定向
旧版本=“1.0.0.0”
newVersion =“2.0.0.0”/>



您可能也会对此感兴趣:

希望有帮助!

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:

Hope that helps!

油焖大侠 2024-10-01 03:26:08

在这种情况下,我倾向于做的是在单元测试时不签署程序集,直到我准备好部署它。这是一个一步过程,您可以转到项目属性并清除“签署程序集”设置。当您重新编译时,下次运行测试时,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文