【问题标题】:Assembly version conflicts for AutoFixture and Moq with NUnit on TeamCity 7TeamCity 7 上 AutoFixture 和 Moq 与 NUnit 的装配版本冲突
【发布时间】:2017-08-09 21:14:47
【问题描述】:

我以前将我的解决方案的所有单元测试都包含在一个库中,最近被拆分出来了。当位于单个程序集中时,所有测试都在本地和 TeamCity 上通过,但分开时会出现版本冲突。

配置:

  • Team City 7.1.5(内部版本 24400)
  • 自动夹具 3.20.2
  • AutoFixture.AutoMoq 3.20.2
  • 起订量 4.2.1402.2112
  • NUnit 2.6.3

我有几个单元测试程序集,它们都引用了一个基础测试库。所有测试程序集都使用上面列出的 NuGet 包。

在开发机器(VS 2015)上运行测试时,所有测试都成功通过。

运行团队城市构建时,抛出以下错误:

System.IO.FileLoadException : 无法加载文件或程序集 'Moq, Version=4.1.1308.2120, Culture=neutral, PublicKeyToken=69f491c39445e920' 或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (来自 HRESULT 的异常:0x80131040)在 Ploeh.AutoFixture.AutoMoq.MockPostprocessor.Create(对象请求,ISpecimenContext 上下文)

我的解决方案中的任何地方都没有引用 Moq 4.1.1308.2120,所以我知道它一定是来自 AutoFixture 的引用。

将 AutoFixture 更新到 3.31.3 没有任何区别。

我在所有测试程序集的 app.config 文件中都有以下绑定重定向:

<dependentAssembly>
  <assemblyIdentity name="Moq" publicKeyToken="69f491c39445e920" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.2.1402.2112" newVersion="4.2.1402.2112" />
</dependentAssembly>

我无法将 Moq 版本降级到 4.1.1308.2120,因为我在测试中使用了 4.2 的功能。

在我看来,Team City 忽略了重定向。我不知道为什么,并且尝试了这些程序集的所有版本组合后,我无法让 Team City 成功运行测试。

【问题讨论】:

  • Team City 如何运行测试?它使用哪个测试运行器?
  • 如果您在开发机器上使用相同的测试运行程序,能否重现该问题?
  • 我刚刚试了一下,所有测试都成功通过了:/
  • 可能是旧版本的 Moq 隐藏在开发机器上的 GAC 中吗?我建议使用 Fuslogvw 查看它从本地加载的位置,然后您可以在 TeamCity 机器上再次尝试,看看它是否在做同样的事情。
  • 如果我有 AutoFixture.AutoMoq 3.20.1 和 AutoFixture 3.20.2,我会收到相同的错误,但对于 AutoFixture 3.20.1。这强烈表明 TeamCity 正在忽略绑定重定向。

标签: nunit teamcity moq autofixture teamcity-7.0


【解决方案1】:

我们也遇到了这个问题。我们在构建服务器上运行了assembly Fusion Logs,并在错误日志中看到了这一点:

    Calling assembly : Ploeh.AutoFixture.AutoMoq, Version=3.50.2.0, Culture=neutral, PublicKeyToken=b24654c590009d4f.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Moq, Version=4.1.1308.2120, Culture=neutral, PublicKeyToken=69f491c39445e920
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///D:/builds/13/s/AssessmentMigratorService.IntegrationPostbuild/bin/Debug/Moq.DLL.
LOG: Assembly download was successful. Attempting setup of file: D:\builds\13\s\AssessmentMigratorService.IntegrationPostbuild\bin\Debug\Moq.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: Moq, Version=4.5.28.0, Culture=neutral, PublicKeyToken=69f491c39445e920
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: The assembly reference did not match the assembly definition found.
ERR: Run-from-source setup phase failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated

所以如果你看到它的这一部分

找不到应用程序配置文件。

我认为正在发生的事情是构建服务器上的单元测试运行程序宿主应用程序没有看到应用程序配置文件,因此程序集绑定重定向无法应用,因为它们位于 app.config 中。

因此,如果您需要使用这些程序集,我看到了 3 种可能的解决方案/解决方法:

  1. 找出为什么 TeamCity 在构建服务器上的单元测试运行程序找不到应用程序配置文件并修复它。
  2. 在构建服务器上使用不同的单元测试运行器。
  3. 将绑定重定向添加到构建服务器的 machine.config。这将在整个机器上全局应用,因此此时不需要在应用程序配置文件中进行重定向。

【讨论】:

    【解决方案2】:

    当我发现我看到此错误的原因时,我感到很尴尬。

    经过8小时的调试,我发现我在TestProjectA中引用了TestProjectB。 Teamcity 被设置为针对它找到的任何 Test*.dll 运行任何 xunit。所以它在 TestProjectA 的 /bin/Debug 文件夹中找到了 TestProjectB.dll。

    但是当TestProjectB.dll在/TestProjectA/bin/Debug中时,没有TestProjectB.dll.config。因此,没有设置任何程序集绑定/重定向。

    我删除了项目引用,因为它是不必要的,并更新了我的 teamcity xunit 运行器以排除没有匹配配置的 dll。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-14
      • 1970-01-01
      • 2019-07-27
      • 2021-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多