How to disable browser launch when building and running in .NET Core
Solution 1
Short Answer
Open the .vscode/launch.json
file and disable launchBrowser
.
More Details
dotnet new webapi
- Open VS Code.
- 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
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.
nmdias
Updated on June 19, 2022Comments
-
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 over 4 yearsWith the
launch.json
in.vscode
folder, this solution won't work. -
Jeppe over 4 yearsSame here -
launchBrowser
has no effect even when setting"enabled": false
. -
Kevin about 4 yearsthe documentation for this is here: aka.ms/VSCode-CS-LaunchJson-WebBrowser