To configure Visual Studio Code to debug C# scripts on OSX, I followed through all the steps listed in the article below:
Debugging C# on OSX with Visual Studio Code
When I tried to debug the sample C# script, Visual Studio Code reported this error:
Could not find the preLaunch task 'build'
As a consequence, I could not inspect the variables defined in the script.
This is a copy of the launch.json file:
{ "version": "0.2.0", "configurations": [ { "name": "Launch console application", "type": "mono", "request": "launch", "preLaunchTask": "build", "program": "${workspaceRoot}/Program.exe", "args": [], "cwd": "${workspaceRoot}", "stopAtEntry": false } ] }
This is a copy of the tasks.json file:
{ "version": "0.1.0", "command": "mcs", "args": [ "-debug", "Program.cs" ], "showOutput": "silent", "taskSelector": "/t:", "tasks": [ { "taskName": "exe", "isBuildCommand": true, "problemMatcher": "$msCompile" } ] }
How do I resolve this?
To start debugging, select F5, or choose the Debug Target button in the Standard toolbar, or choose the Start Debugging button in the Debug toolbar, or choose Debug > Start Debugging from the menu bar. The app starts and the debugger runs to the line of code where you set the breakpoint.
To bring up the Run and Debug view, select the Run and Debug icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D. The Run and Debug view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.
To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.
Open the Debug view by selecting the Debugging icon on the left side menu. Select the green arrow at the top of the pane, next to . NET Core Launch (console). Other ways to start the program in debugging mode are by pressing F5 or choosing Run > Start Debugging from the menu.
You can use the Visual Studio Code to solve it.
When you see the error message, click on the steps below
The VSCode will create a file like it:
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build", "command": "dotnet build", "type": "shell", "group": "build", "presentation": { "reveal": "silent" }, "problemMatcher": "$msCompile" } ] }
It's finished. The VSCode will build the project before run.
The error occurs because Visual Studio Code cannot find any task in the tasks.json with the taskName
value set to 'build'
.
The preLaunchTask
property of the launch.json file defines the task that should be executed before the script is launched. From the question, Visual Studio Code has been configured to run the task build
before launching the script:
preLaunchTask: 'build'
But there's no task named 'build'
in the tasks.json file.
To fix this, you should change the value of the preLaunchTask
property to 'exe'
, which is the build task that has been defined in the tasks.json file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With