0

ASP.NET Core 3 MVC suggests using IHost instead of IWebHost (HostBuilder replaces WebHostBuilder and .NET Generic Host Settings for web apps).

Here is a section of 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"
            }
        },

This doesn't however launch the browser for debugging locally.

  • OS: Linux
  • Editor: VSCode
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
McKabue
  • 2,076
  • 1
  • 19
  • 34
  • I am not too familiar with .net core 3.0, but this stack question seems to do approximately the same thing you are doing via the launch.json https://stackoverflow.com/questions/38576854/how-do-i-launch-the-web-browser-after-starting-my-asp-net-core-application – SomeStudent Nov 05 '19 at 20:06
  • I had looked at it... the answer regards the use of `WebHostBuilder`, am using `HostBuilder`, and I don't want to hard code the stuff to start the URL. – McKabue Nov 05 '19 at 20:17

1 Answers1

0

For launching browser automatically, you could try follow steps below:

  1. Upgrade VS Code to version 1.39.2
  2. Add section below to launch.json

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

Here is a demo full content:

{
// 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}"
        }
    ,]
}
Edward
  • 28,296
  • 11
  • 76
  • 121