3

我正在使用 F# 迈出第一步,并使用 FsUnit.xUnit 进行测试。在 Visual Studio 2017 中,我设置了一个全新的 F# 项目并添加了一个测试项目。到测试项目我 NuGet FsUnit.xUnit 3.0.0 然后 NuGet FsUnit.xUnit.Sample。一切都建立起来。然后测试失败

System.IO.FileLoadException
Could not load file or assembly 'FSharp.Core, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at ApplicationLibraryTest.Tests.Given a LightBulb that has had its state set to true.when I ask whether it is On it answers true.()

在阅读了FsUnit 主页FsUnit 问题后,我添加了一个app.configwith

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-999.999.999.999" newVersion="4.4.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

由于 FSharp.Core.dllbin/debug是 4.4.1.0 版。

再次运行测试给出

System.IO.FileLoadException
Could not load file or assembly 'xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at ApplicationLibraryTest.Tests.Given a LightBulb that has had its state set to true.when I ask whether it is On it answers true.() in D:\git\ApplicationLibrary\ApplicationLibraryTest\FsUnitSample.fs:line 18

所以我添加另一个重定向app.config如下

  <dependentAssembly>
    <assemblyIdentity name="xunit.assert" publicKeyToken="8d05b1bb7a6fdb6c" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-999.999.999.999" newVersion="2.2.0.0" />
  </dependentAssembly>

版本 2.2.0.0 是我在 中找到的 xunit.assert 版本bin\debug

测试再次失败。这次与

System.IO.FileLoadException
Could not load file or assembly 'xunit.assert, Version=2.2.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at ApplicationLibraryTest.Tests.Given a LightBulb that has had its state set to true.when I ask whether it is On it answers true.() in D:\git\ApplicationLibrary\ApplicationLibraryTest\FsUnitSample.fs:line 18

System.IO.FileLoadException
Could not load file or assembly 'xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. 
(Exception from HRESULT: 0x80131040)
  Exception doesn't have a stacktrace

测试项目详细信息:目标 F# 运行时:4.4.1.0

目标框架:4.6.2

我究竟做错了什么?这是一个配置问题,还是我遗漏了什么阻止 FsUnit.xUnit 运行测试?

4

0 回答 0