【问题标题】:ASP.NET Core 3 MVC : IHost not starting browser unlike IWebHostASP.NET Core 3 MVC:IHost 不像 IWebHost 那样启动浏览器
【发布时间】:2019-11-05 20:01:00
【问题描述】:

ASP.NET Core 3 MVC 建议使用IHost 而不是IWebHostHostBuilder replaces WebHostBuilder.NET Generic Host Settings for web apps)。

这里是launch.json的一段

        "launchBrowser": {
            "enabled": true,
            "args": "${auto-detect-url}",
            "windows": {
                "command": "cmd.exe",
                "args": "/C start ${auto-detect-url}"
            },
            "osx": {
                "command": "open"
            },
            "linux": {
                "command": "xdg-open"
            }
        },

但这不会启动浏览器以进行本地调试。

  • 操作系统:Linux
  • 编辑:VSCode

【问题讨论】:

  • 我对 .net core 3.0 不太熟悉,但这个堆栈问题似乎与您通过 launch.json stackoverflow.com/questions/38576854/… 所做的事情大致相同
  • 我看过了……答案是关于WebHostBuilder的使用,我正在使用HostBuilder,我不想硬编码这些东西来启动URL。跨度>

标签: c# visual-studio-code .net-core-3.0 asp.net-core-3.0


【解决方案1】:

要自动启动浏览器,您可以尝试以下步骤:

  1. 将 VS Code 升级到版本1.39.2
  2. 将下面的部分添加到launch.json

        "serverReadyAction": {
            "action": "openExternally",
            "pattern": "^\\s*Now listening on:\\s+(https?://\\S+)"
        },
    

这是一个完整的演示内容:

{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
        {
            "name": ".NET Core Launch (web)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            // If you have changed target frameworks, make sure to update the program path.
            "program": "${workspaceFolder}/bin/Debug/netcoreapp3.0/CoreJWT3_0.dll",
            "args": [],
            "cwd": "${workspaceFolder}",
            "stopAtEntry": false,
            "internalConsoleOptions": "openOnSessionStart",
            "serverReadyAction": {
                "action": "openExternally",
                "pattern": "^\\s*Now listening on:\\s+(https?://\\S+)"
            },
            "launchBrowser": {
                "enabled": true,
                "args": "${auto-detect-url}",
                "windows": {
                    "command": "cmd.exe",
                    "args": "/C start ${auto-detect-url}"
                },
                "osx": {
                    "command": "open"
                },
                "linux": {
                    "command": "xdg-open"
                }
            },
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
            "sourceFileMap": {
                "/Views": "${workspaceFolder}/Views"
            }
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ,]
}

【讨论】:

    猜你喜欢
    • 2018-10-21
    • 1970-01-01
    • 2016-06-26
    • 1970-01-01
    • 1970-01-01
    • 2020-03-30
    • 1970-01-01
    • 2015-11-04
    • 1970-01-01
    相关资源
    最近更新 更多