Debugging of FAKE 5 build scripts

We recommend Visual Studio Code with the Ionide extension for best FAKE tooling support, including proper debugging. The easiest way to debug a script is by using the "Debug" buttons in the FAKE targets outline

Non-Ionide or no Fake.Core.Targets

If you don't use Ionide or if you don't use Fake.Core.Targets the Outline stays empty and you (currently) cannot run or debug via UI. Please see the following sections on how to debug and run.

General considerations

  • Run with more verbose logging -v
  • If an error happens while restoring packages (before even running the script), consider using -vv or -v -v to increase the logging even more.

Currently debugging via the chocolatey installation is not possible. This is because we currently do not distribute the x64 version on x64 versions of windows and the .NET Core debugger currently only supports x64!

Visual Studio Code &&

Debugging works (on windows) in the following way:

  • Download the portable fake distribution and extract it somewhere (for example E:\fake-dotnetcore-portable)

  • Open Visual Studio Code
  • Open "The Debugger" view and add the following configuration

      "name": "Debug My Build Script",
      "type": "coreclr",
      "request": "launch",
      "program": "E:\\fake-dotnetcore-portable\\fake.dll",
      "args": ["run", "--nocache", "--fsiargs", "--debug:portable --optimize-", "build.fsx"],
      "cwd": "${workspaceRoot}",
      "stopAtEntry": false,
      "console": "internalConsole"

    It is important to specify --debug:portable --optimize-
    To get debugging support for .NET Core you need C# for Visual Studio Code

  • Delete the .fake directory

  • Set a breakpoint in your script and run the new configuration

Visual Studio Code && dotnet fake

Add the following lines to your build script:

printfn "Press any key to continue..."
System.Console.ReadKey() |> ignore
  • Delete .fake directory
  • Start your build script via dotnet fake run --nocache build.fsx --fsiargs "--debug:portable --optimize-" and wait for the Press any key to continue... Message
  • Select ".NET Core Attach" in the Visual Studio Code Debugger View
  • Press play and select the dotnet exec --depsfile ".../fake..." process.

Run script without fake.exe (via fsi)

FAKE 5 scripts are not hardwired to the new FAKE 5 runner (even if they look like with the new header). To make them work with FSI all you need to do is to setup a "FAKE-Context":

// Regular header and `#load ".fake/build.fsx/intellisense.fsx"`

#if !FAKE
let execContext = Fake.Core.Context.FakeExecutionContext.Create false "build.fsx" []
Fake.Core.Context.setExecutionContext (Fake.Core.Context.RuntimeContext.Fake execContext)

// Your Script code...

With these lines you can just run fsi build.fsx

You can use this "trick" to run the script via the regular IDE buttons.

To start a new context or cleanup the old one you can use (execute interactively):

let execContext = Fake.Core.Context.FakeExecutionContext.Create false "build.fsx" []
Fake.Core.Context.setExecutionContext (Fake.Core.Context.RuntimeContext.Fake execContext)
val printfn : format:Printf.TextWriterFormat<'T> -> 'T
namespace System
type Console =
  static member BackgroundColor : ConsoleColor with get, set
  static member Beep : unit -> unit + 1 overload
  static member BufferHeight : int with get, set
  static member BufferWidth : int with get, set
  static member CapsLock : bool
  static member Clear : unit -> unit
  static member CursorLeft : int with get, set
  static member CursorSize : int with get, set
  static member CursorTop : int with get, set
  static member CursorVisible : bool with get, set
System.Console.ReadKey() : System.ConsoleKeyInfo
System.Console.ReadKey(intercept: bool) : System.ConsoleKeyInfo
val ignore : value:'T -> unit
val execContext : obj