Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set not to open new web browser tab in vscode when running asp.net core api project

e.g

Every time i key ctrl + f5 or ctrl + shift + f5 to rerun asp.net core api project in vscode,it'll open a new tab.

I expect just restart program without opening new tab.

like image 718
Wei Lin Avatar asked Jul 15 '20 01:07

Wei Lin


People also ask

How to not launch a browser in Visual Studio Code?

How to not launch a browser. Go to the launchSettings.json file in your Visual studio project, look for the following line. This will stop it from launching a browser at all. JavaScript debugging for ASP.Net defines if the browser will open in a new tab or a whole new browser window.

How to open files in the browser in Visual Studio Code?

The easiest way to get the Open in Browser option for Visual Studio Code in Windows is to use an extension. Installing extensions in Visual Studio Code is relatively straightforward, as is using them to open files in the browser. Open your HTML file in the Visual Studio Code Editor. On the far left vertical toolbar, click on “Extensions.”

How to debug ASP NET Core with VSCode?

By default when debugging an ASP.NET Core, VS Code will launch default browser. There is way to choose the browser you would like to use. Here is the code snippet which will add different debug configuration to VS Code. To use this, first you need to open launch.json file. You can find the launch.json file under .vscode folder.

How do I stop a browser from opening in a new tab?

Go to the launchSettings.json file in your Visual studio project, look for the following line. This will stop it from launching a browser at all. JavaScript debugging for ASP.Net defines if the browser will open in a new tab or a whole new browser window.


Video Answer


2 Answers

updated : CLI version (recommand)

It can use dotnet watch to do it .

visul studio code (op want to merge)

If you don't want any browser tab be created,you colud go to .vscode\launch.json remove serverReadyAction and it can deal the problem.

default json :

{
   // 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": [
        {
            //Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
             "serverReadyAction": {
                 "action": "openExternally",
                 "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
            }
        }
    ]
}

just delete or mark serverReadyAction then system'll not open any web browerser tab 🤗

{
   // 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": [
        {
            //Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
            // "serverReadyAction": {
            //     "action": "openExternally",
            //     "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
            //}
        }
    ]
}


P.S

I test set launchBrowser enabled false but it not work,it'll still create new tab.

launchBrowser enabled false launch.json :

{
   // 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": [
        {
            "launchBrowser": {
                "enabled": false    
            },            
            "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/ServerApp.dll",
            "args": [],
            "cwd": "${workspaceFolder}",
            "stopAtEntry": false,
            //Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
            "serverReadyAction": {
                "action": "openExternally",
                "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
            },
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
            "sourceFileMap": {
                "/Views": "${workspaceFolder}/Views"
            }
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

Visual Studio Version :

Every kind of application shows you some kind of UI, prompt, or form. Otherwise, how would user know that’s its up and running.

By default, it’s open a new tab only.

Your project template itself is web API? then how can you expect the web without the browser?

Update: I tried setting the launchBrowser to false in launchSettings.json in Visual studio 2019, it’s launching like the below images.

"profiles": {
  "IIS Express": {
    "commandName": "IISExpress",
    "launchBrowser": false,
    "launchUrl": "default",
    "environmentVariables": {
      "ASPNETCORE_ENVIRONMENT": "Development"
    }
  }

You are setting launchBrowser to false in wrong way, you have to do like this "launchBrowser": false. Its working fine in Asp.Net Core 3.1 API.

You can see in the taskbar

enter image description here enter image description here

like image 109
vivek nuna Avatar answered Nov 14 '22 23:11

vivek nuna


If you don't want any browser tab be created,you colud go to .vscode\launch.json remove serverReadyAction and it can deal the problem.

default json :

{
   // 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": [
        {
            //Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
             "serverReadyAction": {
                 "action": "openExternally",
                 "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
            }
        }
    ]
}

just delete or mark serverReadyAction then system'll not open any web browerser tab 🤗

{
   // 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": [
        {
            //Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
            // "serverReadyAction": {
            //     "action": "openExternally",
            //     "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
            //}
        }
    ]
}


P.S

I test set launchBrowser enabled false but it not work,it'll still create new tab.

launchBrowser enabled false launch.json :

{
   // 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": [
        {
            "launchBrowser": {
                "enabled": false    
            },            
            "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/ServerApp.dll",
            "args": [],
            "cwd": "${workspaceFolder}",
            "stopAtEntry": false,
            //Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
            "serverReadyAction": {
                "action": "openExternally",
                "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
            },
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
            "sourceFileMap": {
                "/Views": "${workspaceFolder}/Views"
            }
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}
like image 28
Wei Lin Avatar answered Nov 14 '22 23:11

Wei Lin