My web.config transformations are not having any effect when I publish my site to my third party host from Visual Studio 2019's publish wizard.
I have a Blazor WebAssembly application and three environments: Development, Staging and Production.
In MyProject\Properties\PublishProfiles
I have a .pubxml
file each for Staging and Production on a third party hosting provider. (I don't need a .pubxml
for Development because I plan on only running that on my local development PC.
Here is what Staging.pubxml
looks like:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<EnvironmentName>Staging</EnvironmentName>
<WebPublishMethod>FTP</WebPublishMethod>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish>staging.myproject.com</SiteUrlToLaunchAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<ProjectGuid>12c14c2e-4d13-4e23-bf64-8e92faf909e9</ProjectGuid>
<publishUrl>ftp.hostingprovider.net</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
<FtpPassiveMode>True</FtpPassiveMode>
<FtpSitePath>myproject-blazor-stag</FtpSitePath>
<UserName>myloginname</UserName>
<_SavePWD>True</_SavePWD>
</PropertyGroup>
</Project>
I would like to insert the following in the <configuration>
element of my web.config
file whenever the project is published using the Staging.pubxml
profile:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="blazor-environment" value="Staging" />
</customHeaders>
</httpProtocol>
</system.webServer>
I should be able to do it using a web.config
transformation.
So, in my project root directory I added an XML tranformation called Web.Staging.config
Here's the content:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<location>
<system.webServer xdt:Transform="InsertIfMissing">
<httpProtocol xdt:Transform="InsertIfMissing">
<customHeaders xdt:Transform="InsertIfMissing">
<add name="blazor-environment" value="Staging"
xdt:Locator="Match(name)"
xdt:Transform="InsertIfMissing" />
</customHeaders>
</httpProtocol>
</system.webServer>
</location>
</configuration>
I was expecting that, when I publish my site using the Staging.pubxml
profile, this Web.Staging.config
transformation would add the missing section to the web.config
file deployed to the third party host. Then, when I load up the Blazor application in a browser, it should be using the settings for the Staging environment. Unfortunately, the transformation is never applied to the web.config
file. I downloaded the file to check, and nothing had been added. Thefore, the Blazor app runs using the settings of the Production environment instead of Staging.
Can anybody see what I did wrong, please?
EDIT: There is now a minimal reproducible sample on my GitHub issue.