Debugging C# Web API for first time in VS Code — fix “don’t have an extension for debugging XML” error

I am trying to run the VS Code debugger for the first time for my .NET 9 web api. When I hit F5 it doesn’t start debugging and I get this message:

You don’t have an extension for debugging XML. Should we find a XML extension in the Marketplace?

So to fix this issue, I asked Github Copilot what to do to make it work. This was it’s response.

Step-by-step solution:

1. Install the official C# extension (if not already done).
2. Avoid focusing on your .csproj file when starting debugging—open one of your C# source files.
3. Create a launch configuration file to explicitly start debugging your web API.

And this was the launch.json file it created.

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": ".NET Launch Web API",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      "program": "${workspaceFolder}/dotnetapivue3.Server/bin/Debug/net9.0/dotnetapivue3.Server.dll",
      "args": [],
      "cwd": "${workspaceFolder}/dotnetapivue3.Server",
      "stopAtEntry": false,
      "serverReadyAction": {
        "action": "openExternally",
        "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
      },
      "env": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  ]
}

I added the file to my project then, opened a controller file. Launched the debugger. After that, the project loaded as expected and I was able to set break points for debugging.

VS Code: Sort lines of code in Ascending (or Descending) Order

Select the code you wish to sort in Visual Studio Code.

Then hit the key combination Ctrl+P and type the greater than sign (>). Next type sort and choose Sort Lines Ascending or choose the Descending option.

Now the lines you’ve previously selected will be sorted by the option you chose. One thing to keep in mind is that if you have lines which have breaks in them, the second line will also be sorted into the mix. Which may mess up formatting for things like CSS Property values.

How to Install Visual Studio Code on Raspberry Pi

Microsoft has a version of Visual Studio Code which will run on the Raspberry Pi OS — formerly known as Raspbian. You can even download it from the APT (Advanced Packaging Tool). And it’s simply 2 lines of code to install:

sudo apt update
sudo apt install code

Afterward, you can launch it from the Programming menu in the GUI or by typing code in the terminal.

And the really nice thing about VS Code being in the APT is that you can update it like any other package on your Pi:

sudo apt update
sudo apt upgrade code

VS Code equivalent to Visual Studio’s Ctrl+m Ctrl+o

Sometimes, when you have a long file, it’s convenient to fold/collapse all the code regions so you can get a big picture of your file. In Visual Studio (the full blown IDE from Microsoft), it’s a simple keyboard shortcut combination

Ctrl+m Ctrl+o

Thankfully, Visual Studio Code has something similar. To fold ALL regions use

Ctrl+k Ctrl+0

Then just use the following to unfold the code file

Ctrl+k Ctrl+j

The nice thing about this is that all the sub regions are folded as well. So you can simply open one region and all the items inside are still folded.

Reference: https://code.visualstudio.com/docs/getstarted/tips-and-tricks#_keyboard-reference-sheets