You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode调试Blazor WASM ASP.NET Core托管项目服务端断点失效求助

Blazor WASM托管项目VSCode中服务端断点无法绑定的解决方法

我创建了一个Blazor WASM ASP.NET Core托管项目,包含Client、Server、Shared三个模块。原本用Visual Studio开发,转到VSCode后遇到问题:客户端代码断点能正常触发,但服务端断点显示“未绑定”,完全无法工作。

代码流程为:razor → 客户端接口 → API → 服务端Controller → 服务端接口实现产品CRUD操作,现在需要调试服务端代码但断点失效。

环境信息

.NET SDK

Version:   6.0.404
Commit:    be4f3ec411

系统环境

OS Name:     Windows
OS Version:  10.0.22621
OS Platform: Windows
RID:         win10-x64
Base Path:   C:\Program Files\dotnet\sdk\6.0.404\

Host信息

Version:      7.0.1
Architecture: x64
Commit:       97203d38ba

已安装的.NET SDK

6.0.404 [C:\Program Files\dotnet\sdk]

已安装的.NET运行时

Microsoft.AspNetCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

当前配置

服务端launchSettings.json

{
    "iisSettings": {
      "windowsAuthentication": false,
      "anonymousAuthentication": true,
      "iisExpress": {
        "applicationUrl": "http://localhost:30765",
        "sslPort": 44311
      }
    },
    "profiles": {
      "SipposM2.Server": {
        "commandName": "Project",
        "dotnetRunMessages": true,
        "launchBrowser": true,
        "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
        "applicationUrl": "https://localhost:7295;http://localhost:5036",
        "environmentVariables": {
          "ASPNETCORE_ENVIRONMENT": "Development"
        }
      },
      "IIS Express": {
        "commandName": "IISExpress",
        "launchBrowser": true,
        "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
        "environmentVariables": {
          "ASPNETCORE_ENVIRONMENT": "Development"
        }
      }
    }
  }

VSCode launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch and Debug Standalone Blazor WebAssembly App",
            "type": "blazorwasm",
            "request": "launch",
            "cwd": "${workspaceFolder}/SipposM2/Server",
            "browser": "edge",
            "url": "https://localhost:7295",
        },
        {
            "name": "Watch",
            "type": "coreclr",
            "request": "launch",
            "cwd": "${workspaceFolder}/SipposM2/Server",
            "program": "dotnet",
            "args": [
                "watch",
                "--project",
                ".",
                "--verbose" // Let's us confirm browser connects with hot reload capabilities
            ],
            "preLaunchTask": "build" // Ensure we don't watch an unbuilt site
        },
        {
            "name": "Attach",
            "type": "blazorwasm",
            "request": "attach",
            "cwd": "${workspaceFolder}/SipposM2/Server",
            "url": "https://localhost:7295",  // Tell launch where to find site
            "timeout": 120000, // Allows time for the site to launch
        }
    ],
        "compounds": [
        {
            "name": "Debug with Hot Reload",
            "configurations": [ "Watch", "Attach" ]
        }
    ]
}

VSCode tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/SipposM2/Server/SipposM2.Server.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "publish",
            "command": "dotnet",
            "type": "process",
            "args": [
                "publish",
                "${workspaceFolder}/SipposM2/Server/SipposM2.Server.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "watch",
            "command": "dotnet",
            "type": "process",
            "args": [
                "watch",
                "run",
                "--project",
                "${workspaceFolder}/SipposM2/Server/SipposM2.Server.csproj"
            ],
            "problemMatcher": "$msCompile"
        }
    ]
}

已尝试的解决方法

在Server.csproj中添加以下配置,但问题未解决:

<DebuggerSupport>true</DebuggerSupport>
<CopyOutputSymbolsToPublishDirectory>true</CopyOutputSymbolsToPublishDirectory>

解决步骤

1. 补充服务端CoreCLR调试配置

当前launch.json只配置了Blazor客户端的调试规则,缺少服务端ASP.NET Core应用的CoreCLR调试配置。在configurations数组中添加以下内容:

{
    "name": "Debug Server",
    "type": "coreclr",
    "request": "launch",
    "preLaunchTask": "build",
    "program": "${workspaceFolder}/SipposM2/Server/bin/Debug/net6.0/SipposM2.Server.dll",
    "args": [],
    "cwd": "${workspaceFolder}/SipposM2/Server",
    "stopAtEntry": false,
    "serverReadyAction": {
        "action": "openExternally",
        "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
    },
    "env": {
        "ASPNETCORE_ENVIRONMENT": "Development"
    },
    "sourceFileMap": {
        "/Views": "${workspaceFolder}/Views"
    }
}

2. 配置同时调试服务端和客户端

如果需要同时调试两端,更新compounds配置:

{
    "name": "Debug Server & Client",
    "configurations": ["Debug Server", "Attach"]
}

3. 确保服务端项目生成调试符号

检查Server.csproj的Debug配置,确保开启符号生成:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DebugType>full</DebugType>
    <DebugSymbols>true</DebugSymbols>
</PropertyGroup>

然后清理并重新生成项目:

dotnet clean
dotnet build --configuration Debug

4. 选择正确的调试启动项

在VSCode调试面板中,选择新增的Debug Server或Debug Server & Client启动调试,不要用原有的Blazor单独启动项。

内容的提问来源于stack exchange,提问作者Edemilorhea

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 08:47:22