appsettings.json launchSettings.json 发布 配置
默认的 JsonConfigurationProvider 会按以下顺序加载配置:
appsettings.jsonappsettings.{Environment}.json:例如,appsettings.Production.json和appsettings.Development.json文件。 文件的环境版本是根据 IHostingEnvironment.EnvironmentName 加载的。 有关详细信息,请参阅在 ASP.NET Core 中使用多个环境。
appsettings.{Environment}.json 值替代 appsettings.json 中的键。 例如,默认情况下:
- 在开发环境中,
appsettings.Development.json配置会覆盖在appsettings.json中找到的值。 - 在生产环境中,
appsettings.Production.json配置会覆盖在appsettings.json中找到的值。 例如,在将应用部署到 Azure 时。
commandName 的值可指定要启动的 Web 服务器。 commandName 可为以下任一项:
IISExpress:启动 IIS Express。IIS:不启动任何 Web 服务器。 IIS 预计可用。Project:启动 Kestrel。
IHostEnvironment.EnvironmentName 可以设置为任意值,但是框架提供了下列值:
- Development:launchSettings.json 文件将本地计算机上的
ASPNETCORE_ENVIRONMENT设置为Development。 - Staging
- Production:没有设置
DOTNET_ENVIRONMENT和ASPNETCORE_ENVIRONMENT时的默认值。
----------------------------------------------------------------
配置文件:Properties\launchSettings.json
{
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"APS.Web": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:57679/"
},
"Production.APS.Web": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
},
"applicationUrl": "http://localhost:57679/"
},
"Staging.APS.Web": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Staging"
},
"applicationUrl": "http://localhost:57680/"
}
},
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:57678/",
"sslPort": 0
}
}
}
——————————————————————————————
发布文件:Properties\PublishProfiles\StagingFolderProfile.pubxml
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<DeleteExistingFiles>true</DeleteExistingFiles>
<ExcludeApp_Data>false</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>bin\Release\net6.0\TestPublish</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<_TargetId>Folder</_TargetId>
<SiteUrlToLaunchAfterPublish />
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<ProjectGuid>13ebc7c8-5427-42f4-bd87-e3b231b23d7b</ProjectGuid>
<SelfContained>false</SelfContained>
<EnvironmentName>Staging</EnvironmentName>
</PropertyGroup>
</Project>
特别注意:非 生产环境(Production),必须在发布文件中设置:<EnvironmentName>Staging</EnvironmentName> ,环境名称,否则始终默认为:Production
参考:https://zhuanlan.zhihu.com/p/575487681
浙公网安备 33010602011771号