2.2 KiB
2.2 KiB
Configure Project Tasks in tasks.json
Use .vscode/tasks.json to define repeatable project commands and optional hooks for debugging.
Minimal File
{
"version": "2.0.0",
"tasks": []
}
Task Fields You Will Use Most
label: Task name shown in VS Code.type: Usuallyshell.command: Executable to run.args: Command arguments.options.cwd: Working directory.group: Mark default build or test tasks.problemMatcher: Parse errors into the Problems panel.isBackground:truefor long-running tasks (for example dev server watch).
Python Project Example
{
"version": "2.0.0",
"tasks": [
{
"label": "App: Run",
"type": "shell",
"command": "uv",
"args": ["run", "uvicorn", "personal_mcp.main:app", "--host", "127.0.0.1", "--port", "8000", "--reload"],
"options": {
"cwd": "${workspaceFolder}"
},
"isBackground": true,
"problemMatcher": []
},
{
"label": "Tests: Pytest",
"type": "shell",
"command": "uv",
"args": ["run", "pytest"],
"options": {
"cwd": "${workspaceFolder}"
},
"group": "test",
"problemMatcher": []
}
]
}
Connect Tasks to Debug Profiles
In launch.json, you can run a task first:
{
"name": "FastAPI: Attach",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "127.0.0.1",
"port": 5678
},
"preLaunchTask": "App: Run"
}
Use this only when startup sequencing is needed.
Task Design Guidelines
- Keep labels stable and descriptive.
- Prefer one task per intent instead of monolithic shell commands.
- Keep shell portability in mind if teammates use multiple OSes.
- Avoid embedding secrets directly in task definitions.
- Mark long-running tasks with
isBackgroundand keep matchers explicit.
Troubleshooting
If a task fails unexpectedly:
- Run the underlying command directly in terminal.
- Confirm
options.cwdpoints to expected workspace root. - Confirm tool availability in environment path.
- Confirm quoting and argument boundaries in
args. - Confirm the task is not blocked by an outdated background process.