VSCode 的 Blazor 客户端 WASM 启动配置

Arc*_*hon 6 visual-studio-code blazor-client-side

在哪里可以找到 .NET Core Launch(Blazor Standalone)启动配置的示例?在你向我推荐这个https://docs.microsoft.com/en-us/aspnet/core/blazor/debug?tabs=visual-studio-code&view=aspnetcore-3.1#vscode 之前,我已经去过那里了。不存在配置文件的实际示例。

小智 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}"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

  • 将 `"${workspaceFolder}/src/Project.UI"` 替换为您的项目位置 (2认同)

Arc*_*hon 0

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

为了打开浏览器,我添加了它"browser": "edge",但它不会自动打开页面,因此我仍然需要手动导航到该网址,但我可以接受。如果有人知道如何开始工作,请随时分享。我的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"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)