【发布时间】:2017-01-23 21:08:26
【问题描述】:
我正在尝试设置一个可以运行 FsUnit 的基本 FAKE F# 项目,但我不知道如何解决 Method not found: 'Void FsUnit.TopLevelOperators.should(Microsoft.FSharp.Core.FSharpFunc`2<!!0,!!1>, !!0, System.Object)' 错误。
我已经阅读了以下似乎相关的帖子,但我显然仍然没有理解它:
- Main github issue
- FSharp.Core packaging guidelines
- FsUnit unable to test portable library (SO)
- Another github issue
我使用以下设置创建了一个 JunkTest 库项目:
paket.dependencies
source https://www.nuget.org/api/v2
nuget FAKE
nuget FSharp.Core
nuget FsUnit
nuget NUnit
nuget NUnit.Console
paket.references
FSharp.Core
FsUnit
NUnit
JunkTest.fs
module JunkTest
open FsUnit
open NUnit.Framework
[<Test>]
let ``Example Test`` () =
1 |> should equal 1 // this does not work
//Assert.That(1, Is.EqualTo(1)) // this works (NUnit)
build.fsx(相关部分)
Target "Test" (fun _ ->
!! (buildDir + "JunkTest.dll")
|> NUnit3 (fun p ->
{p with OutputDir = "TestResults" }
)
)
输出
我看到 FSharp.Core.dll 正在从本地 packages 目录复制:Copying file from "c:\Users\dangets\code\exercism\fsharp\dgt\packages\FSharp.Core\lib\net40\FSharp.Core.dll" to "c:\Users\dangets\code\exercism\fsharp\dgt\build\FSharp.Core.dll".
nunit3-console 执行:c:\Users\dangets\code\exercism\fsharp\dgt\packages\NUnit.ConsoleRunner\tools\nunit3-console.exe "--noheader" "--output=TestResults" "c:\Users\dangets\code\exercism\fsharp\dgt\build\JunkTest.dll"
我尝试在测试项目根目录中添加一个app.config 文件,其中包含以下内容,但它似乎无法解决问题(注意我没有使用 Visual Studio - 我需要做任何特别的事情吗?让项目包含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.3.1.0" newVersion="4.3.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
感谢任何和所有的帮助。
编辑: 解决方案是我没有正确设置 App.config 文件以包含在构建中。所有说“只需将其添加到您的 App.config 文件”的答案都对我没有帮助,因为 VSCode 不会自动将其添加到 fsproj 文件中。
我添加的部分是:
<None Include="App.config" />
在包含其他 <Compile Include=Foo.fs> 行的 ItemGroup 中。
【问题讨论】:
-
app.config文件是否包含在fsproj文件中? -
问题确实出在
app.config文件上——但我在那个“重复”或其他地方找不到的是如何在构建中正确包含app.config文件。正如我在问题中所述,我不使用 Visual Studio,因此需要在fsproj中的有关它的信息对我有所帮助。
标签: f# visual-studio-code f#-fake fsunit