首页 文章

FsUnit:由于它而无法测试可移植库,并且测试项目具有不同的F#.Core版本

提问于
浏览
0

我有一个可移植的库, FSharp.Core 版本是 3.7.4.0 . 安装(在单元测试项目中) FsUnit installs,作为依赖项, FSharp.Core version 3.1.2.5 .

因此,在我的单元测试项目中使用可移植库的功能,例如:

module StammaTests.PieceTests

open Stamma
open NUnit.Framework
open FsUnitTyped

[<Test>]
let ``Testing a Basic function`` () =
    Piece.toChar Black King |> shouldEqual 'k'

产量错误:

结果消息:System.IO.FileLoadException:无法加载文件或程序集'FSharp.Core,Version = 3.7.4.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一 . 定位的程序集的清单定义与程序集引用不匹配 . (HRESULT异常:0x80131040)

尝试将 FSharp.Core 版本从NuGet更新为 4.0.0.1 (甚至在更新时检查两个项目),现在甚至是简单的:

[<Test>]
let ``Testing the test`` () = 1 |> shouldEqual 1

不起作用,给出类似的错误 .

结果消息:System.IO.FileLoadException:无法加载文件或程序集'FSharp.Core,Version = 4.3.1.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一 . 定位的程序集的清单定义与程序集引用不匹配 . (HRESULT异常:0x80131040)

并且第一次失败测试的错误不会改变 .

我觉得我错过了一些非常明显的东西,我发现有几个人有类似的问题,但我不明白他们做了什么来解决它(他们似乎都解决了它 . )例如this one .

编辑

这两个项目都是库,我没有 app.config 文件来添加任何内容 .

2 回答

  • 1

    app.config 文件中添加绑定重定向,将所有 FSharp.Core 绑定重定向到所需的版本 . 例如,要使用版本4.4.0,您的 app.config 文件将如下所示:

    <?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-4.4.0.0" newVersion="4.4.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>
    
  • 0

    我找到了一个实际有用的解决方案here

    基本上,将 App.config 添加到 test 项目,并编写以下内容:

    <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-4.3.1.0" newVersion="4.3.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.6.4.14350" newVersion="2.6.4.14350" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>
    

    它增加了对 Fsharp.CoreNUnit.Framework 的绑定,这与通常只为 Fsharp.Core 添加绑定的解决方案不同 .

相关问题