How to disable browser launch when building and running in .NET Core

Viewed 15701

I'm developing a Web API with .NET Core in macOS with deployment to Linux. I have absolutely no interest in using the browser. However, when building and running from Visual Studio Code (Debug or not), the browser launches every time.

I have to close the tab, remove the browser out of the way, go to Paw, where I actually test the API, then go back to VS Code.

It's really annoying doing this every time.

Isn't there some configuration to disable browser launch?

Thanks

6 Answers

It is changed in version 0.2.0.

Just comment out the below lines.

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

Short Answer

Open the Properties/launchSettings.json file and set "launchBrowser": false. It works for Visual Studio 2019.

More Details

  1. Go to the project location
  2. Open the Properties/launchSettings.json
  3. Set "launchBrowser": false
"profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": false,
      "launchUrl": "weatherforecast",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "MyApi": {
      "commandName": "Project",
      "launchBrowser": false,
      "launchUrl": "weatherforecast",
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }

For me, commenting out the serverReadyAction block in vscode/launch.json worked. I believe the launchBrowser is deprecated.

More info : Starting a Web Browser

enter image description here

In my case, the auto-generated launch.json contained this section:

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

So the browser was keeping launching even if I removed the "launchBrowser" or set its "enabled" property to false.

Deleting the "serverReadyAction" section solved my issue.

Related