在有.net SDK和vscode插件C# dev kit的情况下添加一下连个文件
.vscode/launch.json
{ "version": "0.2.0", "configurations": [ { // 默认:连旧栈 mysql localhost:3306(老数据) "name": "BlogServer 调试 (3306 旧库)", "type": "dotnet", "request": "launch", "projectPath": "${workspaceFolder}/BlogServer/BlogServer.csproj", "launchSettingsProfile": "http", "preLaunchTask": "kill-blogserver" }, { // 8088 端口,与 Docker 的 CSharp 容器(8080)同时运行互不干扰 // 注意:不能用 launchSettingsProfile(其 8080 命令行参数优先级更高),改由环境变量指定端口 "name": "BlogServer 调试 (8088 共存·3306 旧库)", "type": "dotnet", "request": "launch", "projectPath": "${workspaceFolder}/BlogServer/BlogServer.csproj", "preLaunchTask": "kill-blogserver", "env": { "ASPNETCORE_ENVIRONMENT": "Development", "ASPNETCORE_URLS": "http://localhost:8088" } }, { // 连 CSharp-mysql 容器 3307(新库,admin/123456) "name": "BlogServer 调试 (3307 CSharp-mysql 新库)", "type": "dotnet", "request": "launch", "projectPath": "${workspaceFolder}/BlogServer/BlogServer.csproj", "launchSettingsProfile": "http", "preLaunchTask": "kill-blogserver", "env": { "ConnectionStrings__Default": "Server=localhost;Port=3307;Database=blog_db;User=root;Password=root123456;CharSet=utf8mb4;SslMode=None;AllowPublicKeyRetrieval=True" } } ] }.vscode/tasks.json
{ "version": "2.0.0", "tasks": [ { // 启动前结束残留的 BlogServer.exe,否则 bin 下的 dll/exe 被占用会导致编译失败 "label": "kill-blogserver", "type": "shell", "command": "powershell -NoProfile -Command \"Stop-Process -Name BlogServer -Force -ErrorAction SilentlyContinue; exit 0\"", "problemMatcher": [] }, { "label": "build", "type": "process", "command": "dotnet", "args": [ "build", "${workspaceFolder}/BlogServer/BlogServer.csproj" ], "group": { "kind": "build", "isDefault": true }, "problemMatcher": "$msCompile" } ] }看情况选择launch.json调试,如果使用docker前后端分离则要修改前端的上游地址proxy_pass