首页 > 解决方案 > Blazor (WASM) 和 Web Api 分离项目调试

问题描述

我在调试 Blazor Web 程序集项目时遇到问题。

设置:

我的 Web Api 项目中有这两行。

app.UseWebAssemblyDebugging();

app.UseEndpoints(endpoints =>
        {
            endpoints.MapRazorPages();
            endpoints.MapControllers();
            endpoints.MapFallbackToFile("index.html");
        });

启动设置 Web API:

 "API": {
      "commandName": "Project",
      "dotnetRunMessages": "true",
      "launchBrowser": true,
      "launchUrl": "",
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }

启动设置 Blazor WASM:

 "Lab.Web": {
      "commandName": "Project",
      "dotnetRunMessages": "true",
      "launchBrowser": true,
      "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }

当我尝试在 Blazor 项目中的某处放置断点时。我收到这条消息:

“当前不会命中断点。没有为此文档加载任何符号。”

如果我单独运行 Blazor 项目,但我无法访问我的 Web API,我不会收到此消息。

在能够调试 WASM 项目的同时,为 Web API 和 Blazor WASM 共享相同端口的正确方法是什么?

ps:如果这有帮助,我正在使用 VS Studio 16.9.3。

非常感谢您的帮助!

标签: asp.net-coreblazorblazor-webassembly

解决方案


我假设:

  1. 您在 AspNetCore 而不是 IIS 中运行项目。
  2. 您将 API Server 项目作为您的启动项目。
  3. 您处于调试模式。
  4. 您的设置就像托管在 ASPNetCore 模板上的 Web 程序集。

您唯一需要的地方inspectUri是 LaunchSettings.json 中的 API 项目,这是您没有的地方。

在调试模式下启动时,开始可能会很慢,所以给它时间。


推荐阅读