launch.json 與 tasks.json 設定 - daniel-qa/RooCode GitHub Wiki

launch.json 與 tasks.json 設定

launch.json 說明

  • 設定範例:

前端與後端

{
  "version": "0.2.0",
  "compounds": [
    {
      "name": "Debug All",
      "configurations": ["ASP.NET Core", "Vue Dev Server"]
    }
  ],
  "configurations": [
    {
      "name": "ASP.NET Core",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "run-backend",
      "program": "${workspaceFolder}/bin/Debug/net9.0/MyProject.dll",
      "args": [],
      "cwd": "${workspaceFolder}",
      "stopAtEntry": false,
      "serverReadyAction": {
        "action": "openExternally",
        "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
      },
      "env": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    {
      "name": "Vue Dev Server",
      "type": "node-terminal",
      "request": "launch",
      "command": "npm run dev",
      "cwd": "${workspaceFolder}/ClientApp"
    }
  ]
}

主要設定設明

  • compounds 是 Visual Studio Code(VS Code)中的 多配置啟動(Compound Launch)功能的一部分,它允許你同時啟動多個調試配置

這對於需要啟動多個服務(如後端 API 和前端開發伺服器)的開發環境特別有用。

"compounds": [
  {
    "name": "Debug All",
    "configurations": ["Vue Dev Server", "ASP.NET Core"]
  }
]
  • type: "coreclr":表示這是啟動一個 .NET Core 應用。

  • type: "node-terminal":這是用來啟動 Node.js 應用的配置。

  • 執行順序

compounds 裡的配置會依照它們在 configurations 中定義的順序來啟動,越早列出的配置會越早執行。

tasks.json 說明

當你在 launch.json 中設置了 preLaunchTask 並將它設為 "run-backend",VS Code 會查找 tasks.json 中標籤為 "run-backend" 的任務並執行它。

  • tasks.json 設定範例
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "run-backend",
      "type": "process",
      "command": "dotnet",
      "args": ["run"],
      "problemMatcher": "$msCompile",
      "group": "build",
      "presentation": {
        "reveal": "silent"
      }
    },
    {
      "label": "run-frontend",
      "type": "process",
      "command": "npm",
      "args": ["run", "dev"],
      "problemMatcher": [],
      "group": "build",
      "presentation": {
        "reveal": "silent"
      },
       "options": {
        "cwd": "${workspaceFolder}/ClientApp"
      }
    }
  ]
}
  • tasks.json 說明

tasks.json 是 Visual Studio Code 中的一個配置文件,主要用來定義自動化任務,讓你能夠在開發過程中自動執行各種命令行指令。這些任務可以用來執行編譯、測試、啟動服務、運行腳本等工作,並且可以與 launch.json、debugger 等配置協同工作,從而提高開發效率。

  • tasks.json 的主要作用:

自動化命令行任務:

你可以在 tasks.json 中定義各種命令行任務,例如:

編譯程式碼(例如,使用 dotnet build 或 npm run build)。

執行測試(例如,npm run test 或 dotnet test)。

啟動服務(例如,dotnet run 或 npm run start)。

執行自定義腳本(例如,清理資料夾或處理資源)。