如何在Visual Studio 2022预览版调试ASP.NET Core Web API时弹出传统控制台窗口
解决Visual Studio 2022调试ASP.NET Core Web API弹出传统控制台窗口的方法
方案1:手动修改launchSettings.json
在项目的launchSettings.json文件中,给需要启用外部控制台的profile(比如http或https)添加"externalConsole": true配置项即可。修改后的配置示例如下:
"profiles": { "http": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", "applicationUrl": "http://localhost:5184", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, "externalConsole": true }, "https": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", "applicationUrl": "https://localhost:7184;http://localhost:5184", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, "externalConsole": true } }
方案2:通过Visual Studio界面配置
- 右键项目,选择「属性」
- 切换到「调试」选项卡
- 在「控制台」下拉菜单中选择「外部控制台」
- 保存设置后重新启动调试
添加该配置后,调试ASP.NET Core Web API时就会弹出独立的传统控制台窗口,替代Visual Studio的内置终端。VS2019默认启用外部控制台,而VS2022 17.5.0 Preview这类版本默认使用内置终端,通过上述任一方案即可切换回传统控制台模式。
内容的提问来源于stack exchange,提问作者Large
相关产品推荐
相关产品推荐

