◾️はじめに
https://dk521123.hatenablog.com/entry/2025/08/21/143045
を知った際に、Visual Studio Code の tasks.json も学んだので メモしておく
【1】.vscode/tasks.json
* JSON形式で定型のコマンド類を登録し実行できる
【2】Hello World
Step1:.vscode/tasks.jsonの作成
[1] メニュー[Terminal]-[Configure Tasks] を選択 [2] [Create tasks.json file from template]-[Others] を選択 => .vscode/tasks.json が作成される
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "echo", "type": "shell", "command": "echo Hello" } ] }
Step2: タスクの実行
[1] メニュー[Terminal]-[Run Task] を選択 [2] [echo]-[Continue without scanning the task output] を選択 => 「Hello」が表示されるはず
理解を深めるために
[1] .vscode/tasks.json を修正(以下「.vscode/tasks.json (修正後)」参照) [2] メニュー[Terminal]-[Run Task] を選択 [3] [echo3]-[Continue without scanning the task output] を選択 => 「Hello1~3」が表示されるはず
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "echo1", "type": "shell", "command": "echo Hello-1" }, { "label": "echo2", "type": "shell", "command": "echo Hello-2" }, { "label": "echo3", "type": "shell", "command": "echo Hello-3", "dependsOrder": "sequence", "dependsOn":[ "echo1", "echo2" ], } ] }
【3】tasks.jsonの構文
{ "version": "2.0.0", "tasks": [ { "label": "echo", // タスクのラベル "detail": "Helloと出力する", // タスクの説明 "type": "shell", // タスクのタイプ。(e.g. "shell"や"process") "command": "echo", // 実行するコマンド "args": ["Hello"], // コマンドの引数 "group": "build", // ここでbuildを選択するとビルドタスクとして認識。 "presentation": { "reveal": "always", // 出力パネルの表示タイミング "echo": true, // コマンドのエコーを表示するかどうか "focus": false, // タスク実行後に出力パネルにフォーカスを移すかどうか "panel": "shared" // 出力パネルの共有設定 } }, { ... } ] }
参考文献
https://qiita.com/ShortArrow/items/0bacd3a4bcbcbac50e60
https://dev.classmethod.jp/articles/tasks-json-vscode-automation/
https://blog.future.ad.jp/vscode_tasks.json
関連記事
Visual Studio Code ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2019/10/20/230323
GitHub Copilot 〜 copilot-instructions.md 〜
https://dk521123.hatenablog.com/entry/2025/08/21/143045