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

12,845

Solution 1

Short Answer

Open the .vscode/launch.json file and disable launchBrowser.

More Details

  1. dotnet new webapi
  2. Open VS Code.
  3. Add required assets to build and debug.

At this point, there is a .vscode directory that contains a launch.json file. Open that file and disable or delete the following.

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

See also: https://code.visualstudio.com/docs/editor/debugging#_launch-configurations

Solution 2

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+)"
// },

Solution 3

Just to add, it works for Visual Studio 2017 as well (Not only VS Code). The file is called launchSettings.json, and is located inside the Properties folder of the project.

Solution 4

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

Solution 5

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.

Share:
12,845
nmdias
Author by

nmdias

Updated on June 19, 2022

Comments

  • nmdias
    nmdias almost 2 years

    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

  • CodeRed
    CodeRed over 4 years
    With the launch.json in .vscode folder, this solution won't work.
  • Jeppe
    Jeppe over 4 years
    Same here - launchBrowser has no effect even when setting "enabled": false.
  • Kevin
    Kevin about 4 years
    the documentation for this is here: aka.ms/VSCode-CS-LaunchJson-WebBrowser