VSCode中Blazor客户端WASM启动配置

7

1
一样的问题。按照参考链接中提到的文章所说,仍然是这个问题。*'.NET Core Launch (Blazor Standalone)'* 和 '.NET Core Debug Blazor Web Assembly in Chrome'丢失了 - g.pickardou
谢谢,很高兴知道我不是唯一一个迷失的人。 - Archon
3个回答

6
我也曾经遇到过这个问题;在进行调试时,请优先使用“.Net Core”,它应该会自动生成:
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch (Blazor Standalone)",
            "type": "coreclr",
            "request": "launch",
            "program": "dotnet",
            "args": [
                "run"
            ],
            "cwd": "${workspaceFolder}/src/Project.UI",
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            }
        },
        {
            "name": ".NET Core Debug Blazor Web Assembly in Chrome",
            "type": "pwa-chrome",
            "request": "launch",
            "timeout": 30000,
            "url": "https://localhost:5001",
            "webRoot": "${workspaceFolder}/src/Project.UI",
            "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}"
        }
    ]
}

我的 Blazor 项目位于 "/src/Project.UI"。 - John Gold
非常感谢您! - Archon
2
请将 "${workspaceFolder}/src/Project.UI" 替换为您的项目位置。 - Colin Bacon

1

你需要首先为 Blazor WebAssembly 创建一个构建任务(task.json)。

   {
   // See https://go.microsoft.com/fwlink/?LinkId=733558
   // for the documentation about the tasks.json format
   "version": "2.0.0",
   "tasks": [
      {
         "label": "build",
         "command": "dotnet",
         "type": "process",
         "args": [
            "build",
            "${workspaceFolder}/BlazorSVgTest.csproj",
            "/property:GenerateFullPaths=true",
            "/consoleloggerparameters:NoSummary"
         ],
         "problemMatcher": "$msCompile"
      },
   ]
}

然后创建一个启动任务(launch.json),启用调试功能。

{
   // See https://go.microsoft.com/fwlink/?LinkId=733558
   // for the documentation about the tasks.json format
   "version": "2.0.0",
   "tasks": [
      {
         "label": "build",
         "command": "dotnet",
         "type": "process",
         "args": [
            "build",
            "${workspaceFolder}/BlazorSVgTest.csproj",
            "/property:GenerateFullPaths=true",
            "/consoleloggerparameters:NoSummary"
         ],
         "problemMatcher": "$msCompile"
      },
   ]
}

0

好的,在重新审视后,我现在明白了。在 launch.json 中,我需要添加一行 "url": "https://localhost:{PORT}" 并使用 Properties/launchSettings.json 中提到的第一个端口。

为了让浏览器打开,我添加了 "browser": "edge",但它不会自动打开页面,所以我仍然需要手动导航到 URL,但我可以接受这个。如果有人知道如何使其工作,请随时分享。我的 launch.json 如下:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch and Debug Standalone Blazor WebAssembly App",
            "type": "blazorwasm",
            "request": "launch",
            "url": "https://localhost:7051",
            "browser": "edge"
        }
    ]
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接