You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FSharp.Charting维护者求助:FAKE执行NUnit测试时无法找到正确exe路径

Troubleshooting FAKE-NUnit Path Issue in FSharp.Charting

Hey there, let's work through this test failure you're seeing with FAKE and NUnit in the FSharp.Charting repo. The core issue here is that FAKE isn't picking up the correct path to nunit3-console.exe, so let's break down the fixes step by step.

First: Verify the Actual NUnit Path

First double-check that the path you mentioned (packages/NUnit.ConsoleRunner/tools/nunit3-console.exe) is exactly where the executable lives. Sometimes newer versions of NUnit Console Runner nest the exe in a subdirectory like tools/net462 or tools/net6.0 depending on the target framework. Navigate to the packages folder in your repo to confirm the exact path—this will be critical for updating your script.

Fix 1: Update Your build.fsx to Hardcode the NUnit Path

Old versions of FAKE's built-in NUnit helpers might default to looking for the legacy nunit-console.exe instead of nunit3-console.exe, or they might not resolve the package path correctly. The most reliable fix is to explicitly specify the path in your test target.

Replace your existing RunTests target code with something like this:

open Fake.Core
open Fake.IO
open Fake.IO.FileSystemOperators

Target.create "RunTests" (fun _ ->
    // Hardcode the exact path to nunit3-console.exe
    let nunitExePath = __SOURCE_DIRECTORY__ </> "packages" </> "NUnit.ConsoleRunner" </> "tools" </> "nunit3-console.exe"
    // Adjust the test assembly pattern to match your repo's structure
    let testAssemblies = !! "**/bin/Release/**/*Tests.dll" ++ "**/bin/Debug/**/*Tests.dll"
    
    // Execute the NUnit console with your test assemblies
    match Shell.exec nunitExePath (String.concat " " testAssemblies) with
    | 0 -> () // Success
    | _ -> failwith "NUnit tests failed!"
)

If you found the exe in a subdirectory under tools (like net462), update the path to include that, e.g.:

let nunitExePath = __SOURCE_DIRECTORY__ </> "packages" </> "NUnit.ConsoleRunner" </> "tools" </> "net462" </> "nunit3-console.exe"

Fix 2: Check FAKE and NUnit Version Compatibility

If you're using an older version of FAKE (pre-FAKE 5), it might not have full support for NUnit 3.x. Consider upgrading FAKE to the latest stable version to ensure better compatibility with modern NUnit packages.

You can update FAKE via your build.cmd or by modifying the FAKE package reference in your repo's dependencies.

Fix 3: Ensure Packages Are Properly Restored

Sometimes the issue is simply that the NUnit Console Runner package wasn't fully restored. Run the following command before running tests to refresh your packages:

nuget restore

Or if you're using dotnet tools:

dotnet restore

Then delete the packages folder entirely and re-run the restore to rule out corrupted cached packages.

Final Check

After making these changes, run build.cmd RunTests again. If the path was the issue, FAKE should now correctly locate nunit3-console.exe and execute your tests.

内容的提问来源于stack exchange,提问作者Robert Sim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:10:45