@kyanny's blog

My thoughts, my life. Views/opinions are my own.

vscode の launch.json と tasks.json の用途・使い分け方

  • launch.json はプログラムのデバッグ実行のために使う(デバッガーが使える)
  • tasks.json はビルドやテストなどの自動化処理の実行のために使う(デバッガーが使えない)

GitHub Copilot Chat で聞いた

Here's a concise explanation of when to use launch.json and when to use tasks.json in Visual Studio Code:

launch.json

  • Purpose: Configures debugging sessions.
  • Use Case: When you need to run and debug your code interactively, set breakpoints, step through code, and inspect variables.
  • Example: Running and debugging a Python script with the ability to use the integrated debugger.

Example configuration: json { "version": "0.2.0", "configurations": [ { "name": "Python: Run a.py", "type": "python", "request": "launch", "program": "${workspaceFolder}/a.py", "console": "integratedTerminal" } ] }

tasks.json

  • Purpose: Defines tasks for running build processes, scripts, or other command-line operations.
  • Use Case: When you need to automate repetitive tasks such as running tests, building projects, or executing scripts without the need for interactive debugging.
  • Example: Running a Python script or a shell command as part of a build process.

Example configuration: json { "version": "2.0.0", "tasks": [ { "label": "Run a.py", "type": "shell", "command": "python3", "args": [ "${workspaceFolder}/a.py" ], "problemMatcher": [], "group": { "kind": "build", "isDefault": true }, "presentation": { "echo": true, "reveal": "always", "focus": false, "panel": "shared" }, "options": { "cwd": "${workspaceFolder}" } } ] }

Summary

  • Use launch.json: When you need to debug your code interactively.
  • Use tasks.json: When you need to automate tasks like running scripts, building projects, or executing commands without debugging.