How to set up launch.json and task.json for C# debugging in VS Code?

Godot Version

v4.2.1

Question

I’m trying to get debugging going for my C# scripts in VS Code. I followed the guide in the Godot docs here: C# basics — Godot Engine (stable) documentation in English
However, I’m not at all familiar with json. I tried copying the examples as is, and I did create a “GODOT4” environment variable pointing to my Godot executable. When I try to initiate debugging though, it tells me the “program” property (the one that should be using the environment variable) is missing or empty. So obviously it’s not quite as simple as what’s in the docs. What am I missing here?

Hi, I used this guide: How to use C# in Godot | Coco Code Learn

In summary, you have to edit .vscode/launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Play",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
    // Replace your "program" path with path to your Godot installation.
    // Here you can find some examples (remember to replace [user]!):
    // /Users/[user]/Downloads/Godot_mono.app/Contents/MacOS/Godot
    // /Applications/Godot_mono.app/Contents/MacOS/Godot
    // C:/Users/[user]/Downloads/Godot_v4.2.1-stable_mono_win64/Godot.exe
    // C:/Program Files/Godot/Godot.exe
      "program": "[ENTER PATH HERE]",
      "args": [],
      "cwd": "${workspaceFolder}",
      "stopAtEntry": false,
    }
  ]
}

And in .vscode/tasks.json:

{
    "version": "2.0.0",
    "tasks": [
      {
        "label": "build",
        "command": "dotnet",
        "type": "process",
        "args": [
          "build"
        ],
        "problemMatcher": "$msCompile",
        "presentation": {
          "echo": true,
          "reveal": "silent",
          "focus": false,
          "panel": "shared",
          "showReuseMessage": true,
          "clear": false
        }
      }
    ]
  }

It worked for me, I hopes it works for you too.

if you already have the GODOT4 env variable set up (correctly), you can set this up here:

by using

"program": "${env:GODOT4}",