Tasks give every project one-key build and test commands and integrate tool errors into the Problems panel.
A task is a named command VS Code can run for you. Many are auto-detected (npm scripts, Make, Gulp...); run any with "Tasks: Run Task".
Custom tasks live in .vscode/tasks.json:
labelnames it;type: "shell"runscommandin a shell;"process"runs a program directly.groupmarks it as the default build task (Ctrl+Shift+B) or test task.dependsOnchains tasks, withdependsOrder: "sequence"to run them in order.presentationcontrols the terminal: reuse, focus, clear.options.cwdandoptions.envset directory and environment.
Problem matchers parse the task output and turn errors into entries in the Problems panel with clickable locations. Built-in ones include $tsc, $eslint-stylish, $gcc and $go; you can also define a regex-based matcher. For long-running watch tasks (tsc --watch, a dev server), set isBackground: true with a background matcher so VS Code knows when the task is "ready", which matters when another configuration uses it as preLaunchTask.
Tasks are also how debugging setups build before launching. Keep them in the repository so every developer gets the same commands, and prefer calling project scripts (npm run build) rather than duplicating logic in tasks.json.
Example
// .vscode/tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "npx tsc -p .",
"group": { "kind": "build", "isDefault": true },
"problemMatcher": ["$tsc"]
},
{
"label": "test",
"type": "shell",
"command": "npm test",
"group": "test",
"dependsOn": ["build"]
}
]
}Remember
- tasks.json defines labelled commands; Ctrl+Shift+B runs the default build
- problemMatcher turns output into clickable Problems
- isBackground + matcher for watch tasks used as preLaunchTask
Watch out for
- A watch task used as preLaunchTask without isBackground, so the debugger waits forever for it to finish.