VS Code · IDEbeginner
VS Code tasks.json (Task Runner)
A .vscode/tasks.json defining build and test tasks — a default build task, a background watch task with a problem matcher, and a compound that chains them — the file behind Run Task in VS Code.
vscodetasksbuildautomationide
Preview
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "npm run build",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$tsc"
]
},
{
"label": "watch",
"type": "shell",
"command": "npm run watch",
"isBackground": true,
"problemMatcher": [
"$tsc-watch"
]
},
{
"label": "test",
"type": "shell",
"command": "npm test",
"group": "test",
"dependsOn": [
"build"
]
}
]
}AI actions
Documentation
Purpose
Define reusable build, test and watch commands VS Code can run from the Command Palette or wire into a debug preLaunchTask.
When to use
Automating a repo in VS Code: a one-key build, a background watch that surfaces compiler errors as problems, or a chain that builds before testing.
Required fields
- version — the tasks schema version, "2.0.0"
- tasks — the array of task definitions
- label / type / command — per task
Optional fields
- group — mark a task as the default build or test task
- problemMatcher — parse output into the Problems panel
- isBackground — for watch tasks that keep running
- dependsOn — run other tasks first (chaining)
Best practices
- Give exactly one build task group.kind "build" with isDefault true.
- Attach a problemMatcher to watch tasks so errors show in the Problems panel.
- Use dependsOn to compose tasks instead of shell && chains.
Security considerations
- Do not embed secrets in command or args; read them from the environment.
- Be cautious with tasks that run on folder open (runOptions.runOn).
- Review any task that pipes to a shell to avoid command injection from inputs.