运行asp.net core api项目时如何在vscode中设置不打开新的Web浏览器选项卡

IT *_*Han 4 c# asp.net-web-api visual-studio-code asp.net-core

例如

每次我在 vscode 中键入ctrl + f5ctrl + shift + f5重新运行 asp.net core api 项目时,它都会打开一个新选项卡。

我希望只是重新启动程序without opening new tab

viv*_*una 8

更新:CLI 版本(推荐)

它可以dotnet watch用来做。

视觉工作室代码(op要合并)

如果你不想创建任何浏览器标签,你可以去.vscode\launch.json删除serverReadyAction它可以解决问题。

默认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+)"
            }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

只需删除或标记serverReadyAction然后系统将不会打开任何网络浏览器选项卡

{
   // 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+)"
            //}
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)


聚苯乙烯

我测试集launchBrowser enabled false但它不起作用,它仍然会创建新标签。

launchBrowser 启用 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}"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

视觉工作室版本:

每种应用程序都会向您展示某种 UI、提示或表单。否则,用户如何知道它已启动并正在运行。

默认情况下,它仅打开一个新选项卡。

你的项目模板本身就是web API?那么没有浏览器你怎么能期待网络呢?

更新:我试过设置launchBrowserfalse在Visual Studio 2019中launchSettings.json,它的推出,如下面的图像。

"profiles": {
  "IIS Express": {
    "commandName": "IISExpress",
    "launchBrowser": false,
    "launchUrl": "default",
    "environmentVariables": {
      "ASPNETCORE_ENVIRONMENT": "Development"
    }
  }
Run Code Online (Sandbox Code Playgroud)

launchBrowserfalse错误的方式设置,你必须这样做"launchBrowser": false。它在 Asp.Net Core 3.1 API 中运行良好。

你可以在任务栏中看到

在此处输入图片说明 在此处输入图片说明