FsUnit:由于无法测试可移植库,并且无法测试具有不同F#.Core版本的项目 [英] FsUnit: Unable to test portable library due to it and test project having different F#.Core versions
问题描述
我有一个可移植库,其FSharp.Core
版本为3.7.4.0
.安装(在单元测试项目中)FsUnit
作为依赖项安装FSharp.Core
版本3.1.2.5
.
I have a Portable Library, for which the FSharp.Core
version is 3.7.4.0
. Installing (in the Unit Test project) FsUnit
installs, as a dependency, FSharp.Core
version 3.1.2.5
.
由于此,例如,在我的单元测试项目中使用可移植库的功能,
Due to this, using the portable library's functions in my Unit Test project, for example:
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,版本= 3.7.4.0,区域性=中性, PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一.这 定位的程序集的清单定义与程序集不匹配 参考. (来自HRESULT的异常:0x80131040)
Result Message: System.IO.FileLoadException : Could not load file or assembly 'FSharp.Core, Version=3.7.4.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)
试图将FSharp.Core
版本从NuGet升级到4.0.0.1
(甚至在更新时检查两个项目),现在甚至是简单的东西:
Tried updating the FSharp.Core
version from NuGet to 4.0.0.1
(even checking both projects when updating) and now even something simple like :
[<Test>]
let ``Testing the test`` () = 1 |> shouldEqual 1
不起作用,出现类似错误.
doesn't work, giving this similar error.
结果消息:System.IO.FileLoadException:无法加载文件或 程序集'FSharp.Core,Version = 4.3.1.0,Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一.这 定位的程序集的清单定义与程序集不匹配 参考. (来自HRESULT的异常:0x80131040)
Result Message: 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)
第一个失败的测试的错误不会改变.
And the error for the first failing test doesn't change.
我觉得自己似乎很痛苦地缺少一些东西,我发现有几个人遇到类似的问题,但是我不明白他们为解决这个问题做了什么(他们似乎都解决了..),例如这一个.
I feel like I am missing something painfully obvious, and I found several people with similar problems, but I don't understand what they did to solve it (they all seem to have solved it ..) For example this one.
两个项目都是库,我没有要添加任何内容的app.config
文件.
Both projects are libraries and I do not have an app.config
file to add anything to.
推荐答案
I found a solution that actually worked here
基本上,将App.config
添加到 test 项目,并编写以下内容:
Basically, adding an App.config
to the test project, and writing the following:
<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.Core
和NUnit.Framework
都添加了绑定,这与通常只为Fsharp.Core
添加绑定的解决方案不同.
It adds binding to both Fsharp.Core
and NUnit.Framework
, unlike the usual solutions where you only add a binding for Fsharp.Core
.
这篇关于FsUnit:由于无法测试可移植库,并且无法测试具有不同F#.Core版本的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!