You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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重试。
  • 修复损坏的项目模板:
    1. 以管理员身份打开命令提示符;
    2. 运行dotnet new uninstall查看已安装的.NET项目模板,找到对应版本的ASP.NET Core模板(例如Microsoft.DotNet.Web.ProjectTemplates.7.0,根据你使用的.NET版本调整);
    3. 运行dotnet new uninstall [模板包名]卸载损坏的模板;
    4. 运行dotnet new install [模板包名]重新安装官方模板。

手动生成配置(兜底方案)

若上述方法无效,可手动创建launchSettings.json文件:

  1. 在BookStoreApp.API项目的Properties文件夹下新建文件,命名为launchSettings.json;
  2. 粘贴以下默认配置(可按需调整端口号):
{
  "$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"
      }
    }
  }
}
  1. 保存文件后,右键项目选择重新加载项目,配置即可生效。

内容的提问来源于stack exchange,提问作者zeonidas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 11:24:55