如何使 NUnit 尊重 testassemble.dll.config 中的 BindingRedirect?

发布于 2024-08-24 06:27:00 字数 782 浏览 3 评论 0原文

我正在使用 Fluent Nhibernate 1.0 RTM 和 NHibernate 3.0 版本。为此,我需要将以下内容添加到我的 .config 文件中:

  <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="NHibernate" culture="neutral" publicKeyToken="aa95f207798dfdb4"/>
    <bindingRedirect oldVersion="2.1.0.4000" newVersion="3.0.0.1001"/>
  </dependentAssembly>
</assemblyBinding>

当使用 TestDriven.net 插件运行集成测试时,这非常有效,但在 NUnit gui 或控制台运行程序中失败,并出现以下错误:

System.IO.FileLoadException : 无法加载文件或程序集 'NHibernate, Version=2.1.0.4000, Culture =neutral, PublicKeyToken=aa95f207798dfdb4' 或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (HRESULT 异常:0x80131040)

如何让 NUnit 尊重我的 bindingRedirect 并成功运行我的集成测试?

I am using the 1.0 RTM of Fluent Nhibernate, with a 3.0 build of NHibernate. In order to do this, I need to add the following to my .config file:

  <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="NHibernate" culture="neutral" publicKeyToken="aa95f207798dfdb4"/>
    <bindingRedirect oldVersion="2.1.0.4000" newVersion="3.0.0.1001"/>
  </dependentAssembly>
</assemblyBinding>

This works great when running integration tests with the TestDriven.net plugin, but fails in the NUnit gui or console runner with the following error:

System.IO.FileLoadException : Could not load file or assembly 'NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

How do I get NUnit to respect my bindingRedirect and run my integration tests successfully?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

疯了 2024-08-31 06:27:00

在 CI 服务器(具体来说,bamboo)上运行 nunit 时,我遇到了类似的问题。我的理解是,如果 nunit 在自己的进程空间中运行(就像您只是从命令行运行它一样),那么它可以正确读取 .dll.config 程序集绑定重定向。但是,如果您的 CI 服务器在 CI 服务器的进程空间内运行 nunit,那么它会尝试从父进程获取配置。要确保 nunit 在自己的进程空间中运行,请添加命令行选项 /process:multiple。至少,这对我有用,这样 nunit 就能正确找到重定向绑定。

TL;DR:使用命令行选项 /process:multiple

I've had similar issues when running nunit on a CI Server (bamboo, to be specific). The way I understand it is that if nunit is running in its own process space (like you're just just running it from command line), then it can correctly read the .dll.config assembly binding redirects. However, if your CI Server is running nunit within the CI Server's process space, then it tries to get the config from the parent process. To ensure that nunit gets run in its own process space, add the command line option /process:multiple. At least, that is what worked for me so that nunit would properly find the redirect bindings.

TL;DR: use the command line option /process:multiple

凌乱心跳 2024-08-31 06:27:00

关键是将其放入正确的 .config 文件中。请参阅 重定向程序集绑定是否适用于单元使用测试运行程序进行测试?

另一种方法是针对 NHibernate 3.0 编译 Fluent-nhibernate。如果有编译错误,请询问开发团队和/或分叉源代码并使其编译。

The key is putting it in the correct .config file. See Does redirecting assembly binding work for unit testing with a test runner?.

Another approach would be compiling fluent-nhibernate against NHibernate 3.0. If it has compilation errors, ask the dev team and/or fork the source and make it compile.

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