Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 944
nmdias Avatar asked May 13 '17 20:05

nmdias


People also ask

How do I stop Visual Studio from opening my browser?

Go to Project Properties > Debug > Uncheck "Launch Browser" > Save.

How do I turn off hot reload?

This behavior is enabled by default, but you can disable it by clearing the Enable Hot Reload when debugging checkbox on the Build, Execution, Deployment | Hot Reload page of JetBrains Rider settings Ctrl+Alt+S .


4 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+)"
// },
like image 197
陈伟峰 Avatar answered Oct 17 '22 17:10

陈伟峰


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

like image 21
Shaun Luttin Avatar answered Oct 17 '22 17:10

Shaun Luttin


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.

like image 8
chrisgel15 Avatar answered Oct 17 '22 16:10

chrisgel15


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"
      }
    }
  }
like image 8
Jagaa Avatar answered Oct 17 '22 15:10

Jagaa