Skip to content

Instantly share code, notes, and snippets.

@TheAngryByrd
Last active October 22, 2020 13:02
Show Gist options
  • Select an option

  • Save TheAngryByrd/910eca81b3c3ee7018695d8c7d88e859 to your computer and use it in GitHub Desktop.

Select an option

Save TheAngryByrd/910eca81b3c3ee7018695d8c7d88e859 to your computer and use it in GitHub Desktop.
F# Debugging in watch mode

Dotnet watch and debugging

  1. run your application with dotnet watch
  2. Place waitForDebuggerAttached or waitForDebuggerAttachedAndBreak in your main method and save.
  3. App should rebuild printing out pid to attach to
  4. Use your debugger (in our case VSCode) to attach to this process. See launch.json for example attach config. See Tutorial: Debug a .NET Core console application using Visual Studio Code
  5. You'll have to attach everytime you save, you can try using .NET Auto Attach plugin to alleviate this minor pain.

Idea originally from Krzysztof Cieslak

namespace Infrastructure
// search tags: debug, debugger, attach
module Debugging =
let waitForDebuggerAttached (programName) =
#if DEBUG
if not(System.Diagnostics.Debugger.IsAttached) then
printfn "Please attach a debugger for %s, PID: %d" programName (System.Diagnostics.Process.GetCurrentProcess().Id)
while not(System.Diagnostics.Debugger.IsAttached) do
System.Threading.Thread.Sleep(100)
#else
()
#endif
let waitForDebuggerAttachedAndBreak (programName) =
#if DEBUG
waitForDebuggerAttached programName
System.Diagnostics.Debugger.Break()
#else
()
#endif
{
"version": "0.1.0",
"configurations": [
{
"name": ".NET Core Attach to running process",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}",
"justMyCode": false,
"enableStepFiltering": false,
"symbolOptions": {
"searchPaths": [
"http://srv.symbolsource.org/pdb/Public",
"http://srv.symbolsource.org/pdb/MyGet"
],
"searchMicrosoftSymbolServer": true
},
"sourceLinkOptions": {
"*": {
"enabled": true
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment