Visual Studio 2022新建项目未自动添加至launchSettings.json配置的问题
解决Visual Studio 2022社区版无法自动生成launchSettings.json配置的问题
核心设置与模板修复步骤
- 确认项目类型:确保添加的是ASP.NET Core Web API项目(而非类库等无启动配置的项目类型),仅Web类项目会默认生成launchSettings.json。
- 开启VS生成配置选项:打开Visual Studio,依次进入
工具→选项→项目和解决方案→ASP.NET Core,勾选创建新项目时生成launchSettings.json选项,点击确定后重启VS重试。 - 修复损坏的项目模板:
- 以管理员身份打开命令提示符;
- 运行
dotnet new uninstall查看已安装的.NET项目模板,找到对应版本的ASP.NET Core模板(例如Microsoft.DotNet.Web.ProjectTemplates.7.0,根据你使用的.NET版本调整); - 运行
dotnet new uninstall [模板包名]卸载损坏的模板; - 运行
dotnet new install [模板包名]重新安装官方模板。
手动生成配置(兜底方案)
若上述方法无效,可手动创建launchSettings.json文件:
- 在
BookStoreApp.API项目的Properties文件夹下新建文件,命名为launchSettings.json; - 粘贴以下默认配置(可按需调整端口号):
{ "$schema": "https://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:5002", "sslPort": 44302 } }, "profiles": { "http": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", "applicationUrl": "http://localhost:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "https": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", "applicationUrl": "https://localhost:5001;http://localhost:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } }
- 保存文件后,右键项目选择
重新加载项目,配置即可生效。
内容的提问来源于stack exchange,提问作者zeonidas
相关产品推荐
相关产品推荐

