I have the following setup in a Visual Studio 2013 ASP.NET Web API 2 project.
Details for each are found below.
<!-- Web.Develop.config (Web Config Transform) -->
<appSettings>
<add key="ReportInputPath"
value="DevelopPath"
xdt:Transform="SetAttributes"
xdt:Locator="Match(key)" />
</appSettings>
<!-- Web.Release.config (Web Config Transform) -->
<appSettings xdt:Transform="Remove" />
<!-- **Develop.pubxml (Publish Profile) -->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>x64</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>True</ExcludeApp_Data>
<publishUrl>Path</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles
<ExcludeFilesFromDeployment>packages.config</ExcludeFilesFromDeployment>
</PropertyGroup>
</Project>
<!-- Release.pubxml (Publish Profile) -->
<!-- Contents are identical to Develop.pubxml.
This is used to target the Web.Release.Config transform. -->
Whenever I publish the application via the Release publish profile my <appSettings/>
element is successfully removed. However, <appSettings/>
element is removed when the Develop publish profile is run as well.
What I want to understand is:
Why is the <appSettings/>
element being removed when I run the Develop publish profile instead of setting the ReportInputPath value?
And what are the relationships between the between solution/project configurations, publish profiles, and web.config transforms?
The answer to why the <appSettings/>
element is being removed when the Develop publish profile is run is because two transformations are run in the following order.
What is happening is the the first transformation removes the <appSettings/>
element. The second transformation attempts to set the key value in that element, but cannot find it, so it silently fails.
I was able to confirm this by searching through the console output. When the Develop transformation was run there was a warning that the desired element could not be found.
Example (shortened for clarity)
> TransformXml: Applying Transform File: C:\...\MyProject\Web.Develop.config
> C:\...\MyProject\Web.Develop.config(6,4): Warning : No element in the source document matches '/configuration/appSettings'
> TransformXml: Not executing SetAttributes (transform line 9, 10)
The Profile specific web.config transforms and transform preview article by Sayed Ibrahim Hashimi was very helpful in identifying this was the issue.
As far as the relationship between the build configuration, publish profiles, and web.config transform go my current understanding is this.
The key here being that two web.config transformations may be run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With