This document explains how to run and debug your ASP.NET Core Web API project in VS Code.
Make sure you have the following extensions installed in VS Code:
- C# (ms-dotnettools.csharp) ✓ Already installed
- C# Dev Kit (ms-dotnettools.csdevkit) ✓ Already installed
- .NET Install Tool (ms-dotnettools.vscode-dotnet-runtime) ✓ Already installed
src/
├── web-api.sln # Solution file
├── web-api.web/ # Main Web API project
│ ├── Program.cs # Application entry point
│ ├── web-api.web.csproj # Project file
│ ├── web-api.web.http # HTTP test file
│ └── Properties/
│ └── launchSettings.json # Launch configuration
└── web-api.tests/ # Unit tests project
├── UnitTest1.cs
└── web-api.tests.csproj
- Open the project in VS Code
- Press
F5or go to Run and Debug panel (Ctrl+Shift+D) - Select one of the launch configurations:
- Launch Web API - Basic launch
- Launch Web API (HTTP) - HTTP only with browser launch
- Launch Web API (HTTPS) - HTTPS with browser launch
- Attach to Web API - Attach to running process
- Press
Ctrl+Shift+Pto open command palette - Type "Tasks: Run Task"
- Select one of the available tasks:
- build - Build the solution
- run web-api - Run the web API project
- watch - Run with hot reload (file watching)
- test - Run unit tests
- publish - Publish the application
# Navigate to the project directory
cd "c:\Temp\web-api\src\web-api.web"
# Run the application
dotnet run
# Or run with specific profile
dotnet run --launch-profile http
dotnet run --launch-profile httpsThe application currently provides:
- GET /weatherforecast - Returns weather forecast data
- GET /openapi - OpenAPI/Swagger documentation (Development only)
- Open
web-api.web.httpin VS Code - Click "Send Request" above any HTTP request
- View responses in the output panel
# HTTP
curl http://localhost:5113/weatherforecast
# HTTPS
curl https://localhost:7259/weatherforecast- Open any
.csfile (e.g.,Program.cs) - Click in the gutter to the left of line numbers to set breakpoints
- Press
F5to start debugging - Make requests to your API to hit the breakpoints
- Launch Web API: Standard debugging with internal console
- Launch Web API (HTTP): Debug HTTP-only mode with browser launch
- Launch Web API (HTTPS): Debug HTTPS mode with browser launch
- Attach to Web API: Attach debugger to running process
Use the "watch" task for development with automatic reloading:
dotnet watch run --project "c:\Temp\web-api\src\web-api.web"- HTTP: http://localhost:5113
- HTTPS: https://localhost:7259
- OpenAPI/Swagger (Development): http://localhost:5113/openapi
dotnet build "c:\Temp\web-api\src\web-api.sln"dotnet test "c:\Temp\web-api\src\web-api.tests"dotnet publish "c:\Temp\web-api\src\web-api.sln"The following configuration files have been created in .vscode/:
- tasks.json - Build, run, test, and watch tasks
- launch.json - Debug configurations
- settings.json - Project-specific settings
- Port already in use: Change ports in
Properties/launchSettings.json - HTTPS certificate issues: Run
dotnet dev-certs https --trust - Build errors: Ensure .NET 9.0 SDK is installed
- Extension issues: Restart VS Code or reload window
# Check .NET version
dotnet --version
# Restore packages
dotnet restore
# Clean build
dotnet clean && dotnet build
# Trust HTTPS certificate
dotnet dev-certs https --trust