Visual Studio Code: Could not find the preLaunchTask 'build'?
Change tasks.json as below.
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"command": "",
"args": [],
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "shell",
"args": [
"build"
],
"options": {
"cwd": "${workspaceRoot}"
},
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"problemMatcher": "$msCompile"
}
]
}
Yet another reason for this error could be, that the used launch configuration is defined inside my_project.code-workspace file (not in launch.json file).
In such case the tasks.json is not used, but tasks must be defined inside the my_project.code-workspace file.
This might be a "feature", but it behaves as a bug, because:
- tasks doc says: Workspace or folder specific tasks are configured from the tasks.json file in the .vscode folder for a workspace.
- The error "Could not find task 'xxx'." dialog window offers button:
Configure Task
which then opens or offer to create file ./.vscode/tasks.json - There is no mention or visible hint while editing tasks.json file, that it will not be used.
This in comparison with e.g. editing setting.json, where in such case text is dimmed and on hover a message says: "This setting cannot be applied in this workspace. It will be applied when you open the containing workspace folder directly."
If a debugging session is started using debug config: my_debug_config (workspace), only tasks defined in my_project.code-workspace file are used.
But while still having the same workspace opened, selecting debug config: dir_debug_config (my_dir), which is defined in the launch.json file, will then use tasks from the tasks.json file.
For me, it works to restart VS Code after tasks.json
and/or launch.json
files creation.
Also note, that you need to update "program"
settings in launch.json
with the path to dlls.