gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 18:43:31 24 4
gpt4 key购买 nike

例如
每次我在 vscode 中键入 ctrl + f5ctrl + shift + f5 以重新运行 asp.net core api 项目时,它都会打开一个新选项卡。
我希望只需重新启动程序 without opening new tab

最佳答案

更新:CLI 版本(推荐)
它可以使用 dotnet watch 来做到这一点。

视觉工作室代码(op要合并)
如果你不想创建任何浏览器选项卡,你可以去 .vscode\launch.json remove 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 启用 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}"
}
]
}

视觉工作室版本:
每种应用程序都会向您展示某种 UI、提示或表单。否则,用户如何知道它已启动并正在运行。
默认情况下,它仅打开一个新选项卡。
你的项目模板本身就是web API?那么没有浏览器你怎么能期待网络呢?
更新 :我尝试在 Visual Studio 2019 的 launchSettings.json 中将 launchBrowser 设置为 false,它的启动如下图所示。
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": false,
"launchUrl": "default",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
您以错误的方式将 launchBrowser 设置为 false ,您必须这样做 "launchBrowser": false 。它在 Asp.Net Core 3.1 API 中运行良好。
你可以在任务栏中看到
enter image description here
enter image description here

关于c# - 运行asp.net core api项目时如何在vscode中设置不打开新的Web浏览器选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62906238/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com