NUnit 保留 运行 错误版本的 .dll

NUnit keeps running the wrong version of a .dll

我正在使用 NUnit 2.6.4 测试 运行ner。我正在 运行ning 来自加载我的 .csproj 测试的 .nunit 项目文件。它使 运行 错误的依赖版本。
背景:

我有使用 NLog 工具的 castle windsor 3.3。我正在使用 NLog 3.2。默认情况下,Windsor 会尝试加载 NLog 2.0 并会抛出错误 "Can't load NLog 2.0"。因此,我将以下内容添加到我的 exe 文件的 app.config 文件中,以告诉 Windsor 加载 NLog 3.2:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>

现在,我来到我的 NUnit。我正在尝试 运行 我的集成测试(我的单元和功能测试很好,因为我们在这些测试中不使用 IoC),在集成测试中,我们使用 Windsor IoC 来确保一切正常。当我 运行 这个集成测试时,我不断收到关于 "Can't find NLog 2.0"。我已确保以上内容在我的 test.dll app.config 中,并尝试将其添加到 nunit 测试 运行ner 配置文件中。还是不行。我怎样才能让 NUnit 确保在测试 运行 时间找到并应用此设置?

将以下内容添加到 .nunit 项目文件可解决此问题:

configfile="Hl7ic.Engine.Test.dll.config"

即使在 test.dll.config 中正确设置了上述运行时配置设置,nunit 项目也不知道使用 test.dll.config 文件。我一直认为它是 nunit 隐式知道的,但显然它需要显式设置。

在每个 VS 项目中都有一个 'obj' 文件夹,VS 在其中保存程序集引用缓存。有时这个缓存就是问题所在。对于这个问题,我有脚本,您可以在构建之前从 PowerShell 安全地 运行。

Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse } 

运行 当你在你的解决方案文件夹中时这个脚本。此脚本将递归地获取解决方案的所有 bin 和 obj 文件夹并将它们删除。当您重建解决方案时,它将生成全新的程序集引用缓存,您的问题可能会得到解决。

还要确保您已经删除了以前版本的包的文件夹。当您更新项目中的包时,其文件夹不会自动删除,这也可能导致问题。

我遇到了 newtonsoftJson 包 dll 的问题,并以这种方式解决了它。