例如
每次我在 vscode 中键入ctrl + f5
或ctrl + shift + f5
重新运行 asp.net core api 项目时,它都会打开一个新选项卡。
我希望只是重新启动程序without opening new tab
。
例如
每次我在 vscode 中键入ctrl + f5
或ctrl + shift + f5
重新运行 asp.net core api 项目时,它都会打开一个新选项卡。
我希望只是重新启动程序without opening new tab
。
它可以dotnet watch
用来做它。
如果您不想创建任何浏览器选项卡,您可以去.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+)"
}
}
]
}
只需删除或标记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+)"
//}
}
]
}
附言
我测试集launchBrowser enabled false
但它不起作用,它仍然会创建新标签。
launchBrowser 启用了错误的 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}"
}
]
}
每种应用程序都会向您显示某种 UI、提示或表单。否则,用户怎么会知道它已经启动并正在运行。
默认情况下,它只打开一个新标签。
您的项目模板本身就是 Web API?那么你怎么能指望没有浏览器的网络呢?
更新:我尝试在 Visual Studio 2019 的 launchSettings.json 中设置为launchBrowser
,false
它的启动如下图所示。
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": false,
"launchUrl": "default",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
你设置错误,你必须这样launchBrowser
做。它在 Asp.Net Core 3.1 API 中运行良好。false
"launchBrowser": false
你可以在任务栏中看到
如果您不想创建任何浏览器选项卡,您可以去.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+)"
}
}
]
}
只需删除或标记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+)"
//}
}
]
}
附言
我测试集launchBrowser enabled false
但它不起作用,它仍然会创建新标签。
launchBrowser 启用了错误的 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}"
}
]
}
在设置 vscode 文件并添加到 launch.json 之后
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/Parto.Web/bin/Debug/net5.0/Parto.Web.dll",
"args": [],
"cwd": "${workspaceFolder}/Parto.Web",
"stopAtEntry": false,
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Launch - Chrome",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/Parto.Web/bin/Debug/net5.0/Parto.Web.dll",
"args": [],
"cwd": "${workspaceFolder}/Parto.Web",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start \"\" \"C:/Program Files/Google/Chrome/Application/chrome.exe\" ${auto-detect-url}"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:5000"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Parto.Web/Views"
}
},
和 settings.json
{
"omnisharp.path": "latest",
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[csharp]": {
"editor.defaultFormatter": "ms-dotnettools.csharp"
}
}
并将其添加到omnisharp.json
"MSBuild": {
"UseLegacySdkResolver": true}
在 VS Code 终端中
第一个 dotnet 构建
第二个 dotnet 运行“Web 项目地址”
然后在成功运行项目后
通过 cmd.exe /C 启动浏览器 start http://localhost:5000