Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find the preLaunch task 'build'

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?

like image 750
gnerkus Avatar asked Mar 13 '16 20:03

gnerkus


People also ask

How to Debug c# code in Visual Studio code?

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.

How to get Run button in VS code?

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.

How to add breakpoint in Visual Studio code?

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.

How to use Debug Console in Visual Studio code?

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.


2 Answers

You can use the Visual Studio Code to solve it.

When you see the error message, click on the steps below error sample

  1. Configure Task
  2. Create tasks.json file from template
  3. NET Core Executes .NET Core build commands

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.

like image 94
Jeferson Tenorio Avatar answered Sep 25 '22 19:09

Jeferson Tenorio


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.

like image 25
gnerkus Avatar answered Sep 24 '22 19:09

gnerkus