← All articles
Tools1 min read

Automating Work with VS Code Tasks

Stop retyping the same build and test commands. VS Code tasks let you define, chain, and bind them to keystrokes.

S

Swapnika Voora

Author

If you find yourself flipping to a terminal to run the same command dozens of times a day, a VS Code task can do it for you — with output parsing, chaining, and a keybinding.

Define a task

Tasks live in .vscode/tasks.json. A shell task just wraps a command line.

.vscode/tasks.json
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build",
      "type": "shell",
      "command": "npm run build",
      "group": { "kind": "build", "isDefault": true },
      "problemMatcher": ["$tsc"]
    }
  ]
}

The problemMatcher parses compiler output into the Problems panel, so errors become clickable links to the offending line.

Chain tasks together

dependsOn lets you compose tasks. Set dependsOrder to run them in sequence rather than in parallel.

chained.json
{
  "label": "ci",
  "dependsOrder": "sequence",
  "dependsOn": ["lint", "build", "test"]
}

Run them fast

Bind your most-used task to a key in keybindings.json so it's one keystroke away.

keybindings.json
{
  "key": "ctrl+shift+b",
  "command": "workbench.action.tasks.runTask",
  "args": "build"
}

Takeaways

  • Tasks capture repeatable commands in version-controlled config.
  • A problemMatcher turns raw output into navigable errors.
  • Chain with dependsOn and bind the common ones to keystrokes.

Because tasks.json is committed, everyone on the team gets the same automation for free.

#vs-code#automation#productivity

More in Tools