NUnit无法引用Moq,仅在项目上

本文关键字:项目 Moq 引用 NUnit | 更新日期: 2023-09-27 18:18:46

我有一个测试程序集。如果我将测试程序集加载到NUnit中,则所有测试都成功。

如果我然后将该测试保存为一个项目,我开始得到159个错误与Moq的引用。

项目文件如下所示

<NUnitProject>
  <Settings activeconfig="Default" />
  <Config name="Default" binpathtype="Auto">
    <assembly path="My.Assembly.Name.dll" />
  </Config>
</NUnitProject>

错误是

My.Test.Name:
System.IO.FileLoadException : Could not load file or assembly
'Moq, Version=4.0.812.4, Culture=neutral, PublicKeyToken=69f491c39445e920' or
one of its dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)

错误本身是合理的。我们使用的是来自NuGet的v4.0.10827,因此您不会期望它找到v4.0.812.4。问题是:为什么它寻找,为什么只有当我使用。nunit项目文件?

Test程序集没有引用旧版本,并且解决方案中没有其他程序集引用它。

NUnit无法引用Moq,仅在项目上

尝试将.nunit项目文件重命名为My.Assembly.Name.dll。nunit,我有。nunit项目没有找到应用程序配置文件的测试程序集的问题,这就是我如何解决它。