VS Code Debug Setup
Workflow
Step 1 — Scan projects
Glob: **/*.csproj (exclude bin/ and obj/ directories)
Read each .csproj and classify:
- Web project:
Sdk attribute is Microsoft.NET.Sdk.Web
- Test project:
PackageReference contains xunit, MSTest, or NUnit (case-insensitive)
- Class Library: everything else — skip, no launch config needed
Also collect per project:
<TargetFramework> value (e.g. net9.0)
- Project directory (path relative to workspace root)
- Project name (
.csproj filename without extension)
Step 2 — Read port settings
For each web project, read {ProjectDir}/Properties/launchSettings.json:
- Find the first non-IIS-Express profile (
commandName is not "IISExpress")
- Take
applicationUrl — full value (e.g. https://localhost:5001;http://localhost:5000)
- Also extract
{httpsUrl} — the https-only portion (e.g. https://localhost:5001)
- If
launchUrl is present (e.g. swagger), record it for use in uriFormat
Step 3 — Generate tasks.json
For each web + test project, one "build: {ProjectName}" task.
Add a "build: solution" task (isDefault: true) that builds the whole .sln (Glob *.sln to get the path).
For each web project, also add a "watch: {ProjectName}" background task using dotnet watch for hot reload.
See REFERENCE.md § tasks.json.
Step 4 — Generate launch.json
For each web project, generate two launch configurations in sequence:
- Standard launch:
type: coreclr, preLaunchTask: "build: {ProjectName}", full .dll path as program, cwd set to project dir, console: "integratedTerminal", sourceFileMap, and serverReadyAction; use uriFormat: "{httpsUrl}/{launchUrl}" when launchUrl is present, otherwise "{httpsUrl}/"
- Hot Reload launch:
program: "dotnet", args: ["watch", "--project", ..., "--non-interactive", "run", "--no-restore", "--", "--urls={applicationUrl}"], no preLaunchTask, cwd set to workspace root, console: "integratedTerminal", sourceFileMap, and serverReadyAction
For each test project: one launch config with program: "dotnet", args: ["test", ...], console: "integratedTerminal".
Always append an "Attach to Process" config at the end.
≥ 2 web projects: add two compounds entries:
- Standard compound — launches all web projects using their standard configs
- Hot Reload compound — launches all web projects using their Hot Reload configs
See REFERENCE.md § launch.json.
Step 5 — Write files
mkdir -p .vscode (if not exists)
- Write
.vscode/tasks.json
- Write
.vscode/launch.json
- Report each web project name, its URL, and confirm that standard + hot reload configs were generated
1---2name: vscode-debug-setup3description: Automatically generate .vscode/launch.json and .vscode/tasks.json debug configurations for .NET projects, with browser auto-open, hot reload (dotnet watch) support, and multi-project compound launch support. Use when user asks to create VS Code debug files, set up debugging, configure launch.json or tasks.json for a .NET project, or mentions "debug 設定"、"除錯設定"、"launch.json"、"建debug檔"、"hot reload"、"dotnet watch"。4---56# VS Code Debug Setup78## Workflow910### Step 1 — Scan projects1112```13Glob: **/*.csproj (exclude bin/ and obj/ directories)14```1516Read each `.csproj` and classify:17- **Web project**: `Sdk` attribute is `Microsoft.NET.Sdk.Web`18- **Test project**: `PackageReference` contains `xunit`, `MSTest`, or `NUnit` (case-insensitive)19- **Class Library**: everything else — skip, no launch config needed2021Also collect per project:22- `<TargetFramework>` value (e.g. `net9.0`)23- Project directory (path relative to workspace root)24- Project name (`.csproj` filename without extension)2526### Step 2 — Read port settings2728For each **web project**, read `{ProjectDir}/Properties/launchSettings.json`:29301. Find the first non-IIS-Express profile (`commandName` is not `"IISExpress"`)312. Take `applicationUrl` — full value (e.g. `https://localhost:5001;http://localhost:5000`)323. Also extract `{httpsUrl}` — the https-only portion (e.g. `https://localhost:5001`)334. If `launchUrl` is present (e.g. `swagger`), record it for use in `uriFormat`3435### Step 3 — Generate tasks.json3637For each **web + test project**, one `"build: {ProjectName}"` task.38Add a `"build: solution"` task (`isDefault: true`) that builds the whole `.sln` (Glob `*.sln` to get the path).39For each **web project**, also add a `"watch: {ProjectName}"` background task using `dotnet watch` for hot reload.4041See [REFERENCE.md § tasks.json](REFERENCE.md#tasksjson-template).4243### Step 4 — Generate launch.json4445For each **web project**, generate **two** launch configurations in sequence:461. **Standard launch**: `type: coreclr`, `preLaunchTask: "build: {ProjectName}"`, full `.dll` path as `program`, `cwd` set to project dir, `console: "integratedTerminal"`, `sourceFileMap`, and `serverReadyAction`; use `uriFormat: "{httpsUrl}/{launchUrl}"` when `launchUrl` is present, otherwise `"{httpsUrl}/"`472. **Hot Reload launch**: `program: "dotnet"`, `args: ["watch", "--project", ..., "--non-interactive", "run", "--no-restore", "--", "--urls={applicationUrl}"]`, no `preLaunchTask`, `cwd` set to workspace root, `console: "integratedTerminal"`, `sourceFileMap`, and `serverReadyAction`4849For each **test project**: one launch config with `program: "dotnet"`, `args: ["test", ...]`, `console: "integratedTerminal"`.50Always append an "Attach to Process" config at the end.5152**≥ 2 web projects**: add two `compounds` entries:531. **Standard compound** — launches all web projects using their standard configs542. **Hot Reload compound** — launches all web projects using their Hot Reload configs5556See [REFERENCE.md § launch.json](REFERENCE.md#launchjson-templates).5758### Step 5 — Write files59601. `mkdir -p .vscode` (if not exists)612. Write `.vscode/tasks.json`623. Write `.vscode/launch.json`634. Report each web project name, its URL, and confirm that standard + hot reload configs were generated