ASP.NET Core双Profile的launchsettings.json配置失效问题求助
修复launchsettings.json双Profile启动失败问题
你的配置存在几个致命的结构错误,导致合并后无法启动:
- 错误将多个独立启动配置(比如
TrainingAPP_API、https、IIS Express)嵌套在了Development和Production节点下,profiles对象下的每个节点必须是独立的启动Profile,不能互相嵌套。 $schema和iisSettings是全局根层级配置,不该放到每个Profile内部。- Production环境的
ASPNETCORE_ENVIRONMENT错误设置为Development,违背了生产环境的配置意图。 - 硬编码
executablePath完全没必要,commandName: "Project"类型的配置会自动识别程序集路径。
修复后的正确配置如下:
{ "$schema": "https://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:56132/", "sslPort": 44328 } }, "profiles": { "Development": { "commandName": "Project", "dotnetRunMessage": true, "launchBrowser": true, "launchUrl": "swagger", "applicationUrl": "https://localhost:7001;http://localhost:5186", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "Development (HTTPS)": { "commandName": "Project", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, "dotnetRunMessages": true, "applicationUrl": "https://localhost:7064;http://localhost:5050" }, "Development (IIS Express)": { "commandName": "IISExpress", "workingDirectory": "C:\\Users\\jacob\\Desktop\\C#\\TrainingApp", "launchBrowser": true, "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "Production": { "commandName": "Project", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Production" }, "applicationUrl": "http://localhost:5050" }, "Production (HTTPS)": { "commandName": "Project", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Production" }, "dotnetRunMessages": true, "applicationUrl": "https://localhost:7064;http://localhost:5050" }, "Production (IIS Express)": { "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Production" } } } }
说明:
- 把原来嵌套的子配置都改成
profiles下的独立Profile,并给每个Profile起清晰的名字,方便区分环境和启动方式。 - 全局配置
$schema和iisSettings移到根节点。 - 修正Production环境的环境变量为
Production。 - 去掉不必要的
executablePath配置,让dotnet自动处理程序启动路径。
内容的提问来源于stack exchange,提问作者Jacopo Grazioli
相关产品推荐
相关产品推荐

