I'm trying to configure ASP.NET Core project publication profile for deployment to staging environment. There's preconfigured ASPNETCORE_ENVIRONMENT variable set on server, but whatever I try Visual Studio keeps adding ASPNETCORE_ENVIRONMENT variable definition to publishing web.config file. The only way to eliminate it is to delete from launchSettings.json.
This causes several issues:
- Although docs.microsoft.com says this option should completely override the environment variable, in fact the value of HostingEnvironment.EnvironmentName propery is set to "Staging;Environment", concatenated values of environment variable and web.config setting.
- That in consequesce prevents apropriate appsettings.{environment}.json from load and breaks all environment aware logic.
- I'd prefer to keep ASPNETCORE_ENVIRONMENT in launchSettings.json for debugging.
I could not find any setting that controls this behaviour. Is there any?
This is my .pubxml
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Release.Main</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<ProjectGuid>433bb565-5e85-4f1a-9dd4-a7f437fdb534</ProjectGuid>
<SelfContained>false</SelfContained>
<_IsPortable>true</_IsPortable>
<MSDeployServiceURL>http://192.168.0.22</MSDeployServiceURL>
<DeployIisAppPath>auth/main</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>RemoteAgent</MSDeployPublishMethod>
<EnableMSDeployBackup>True</EnableMSDeployBackup>
<_SavePWD>False</_SavePWD>
</PropertyGroup>
</Project>
launchSettings.json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iis": {
"applicationUrl": "https://localhost/DocShellWeb.Sts",
"sslPort": 0
}
},
"profiles": {
"DocShellWeb.Sts": {
"commandName": "IIS",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Deployed web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="..." arguments="..." stdoutLogEnabled="false" hostingModel="InProcess" stdoutLogFile=".\logs\stdout">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 706412a5-be0d-452d-a9b0-ce00d799f990-->
<EnvironmentName>Development</EnvironmentName>
in yourpubxml
file. – jpgrassienvironmentVariables
section in your generatedWeb.Config
– jpgrassiprofile
and set to FileSystem, just to test things out? – jpgrassi