One of the key features of the Visual Studio Code is its great debugging support. It has built-in debugging support for languages and runtimes including C#, PHP, Ruby, Go, Python, C++, PowerShell, and many others.
Look for Debuggers extensions in VS Code Marketplace or select Install Additional Debuggers in the top-level Run menu.
Debug and Release are .NET Core's built-in build configurations. You use the Debug build configuration for debugging and the Release configuration for the final release distribution.
By default, Visual Studio Code launch settings use the Debug build configuration, so you don't need to change it before debugging.
To bring up the Run view, select the Run icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut
If you are running and debugging for the first time then debugging is not yet configured.
To run or debug a simple app in VS Code, select Run and Debug on the Debug start view or press F5 and VS Code will try to run your currently active file.
VS Code will try to automatically detect your debug environment, but if this fails, you will have to choose it manually, select .NET Core.
It will create a
.vscode folder and add the
launch.json file to your workspace.
The Run view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.
A breakpoint temporarily interrupts the execution of the application before the line with the breakpoint is executed. To set a breakpoint on any line you can either click in the left margin of the code window or press
F9 or choose Run > Toggle Breakpoint from the menu while the line of code is selected.
Visual Studio Code indicates the line on which the breakpoint is set by displaying a red dot in the left margin.
To start the debugging, select the green arrow at the top of the pane, next to .NET Core Launch (console).
The Debug Console window lets you interact with the application you are debugging. Let's enter
sum in the typing area and press enter, it will display the value of that variable.
You can change the value of variables to see how it affects your program. Let's type
sum = 20 and you will see the value is changed.
Once a debug session starts, the Debug toolbar will appear on the top of the editor.
Variables can be inspected in the VARIABLES section of the Run view or by hovering over their source in the editor.
Variables and expressions can also be evaluated and watched in the Run view's WATCH section.