The relationship between solution configuration, profile publishing, and web.config transformations

I have the following setup in an ASP.NET Web API 2 project for Visual Studio 2013.

  • Web.Develop.config web transform to set application key value
  • Web.Release.config web transform to remove the application settings key.
  • Develop.pubxml to convert to Web.Develop.config conversion
  • Release.pubxml for conversion to Web.Release.config transform

Details for each of them are given 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 an application through a publication publish profile, my <appSettings/> element is successfully deleted. However, the <appSettings/> element is deleted when the publication publish profile is launched.

I want to understand:

Why is the <appSettings/> element deleted when I run the publication publish profile instead of setting the ReportInputPath value?

And what is the relationship between solution / project configurations, profile publishing, and web.config transformations?

+6
source share
1 answer

The answer to the question of why the <appSettings/> element is deleted when the publication publish profile is launched, is that the two conversions are performed in the following order.

  • Web.Release.config. This is because the configuration goal in the Develop.pubxml file is to configure the Release assembly.
  • Web.Develop.config. This is done because the name of the publication profile (Develop) matches the name of the transformation file.

What happens, the first conversion removes the <appSettings/> element. The second conversion tries to set the key value in this element, but cannot find it, so it silently fails.

I was able to confirm this by doing a search through console output. When the development transformation was completed, there was a warning that the desired item was not 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) 

A profile specific to web.config converts and converts the preview . Sayyid Ibrahim Hashimi's article was very helpful in defining this issue.

As for the relationship between assembly configuration, publishing profiles, and web.config conversion, my current understanding is this.

  • Publishing profiles contains (among other things) a configuration goal
  • Publishing profiles first starts the conversion, which maps to the specified destination configuration name, if exists
  • Publish profiles then start a conversion that displays their publication publish name, if exists

The key here is that two web.config conversions can be performed.

+6
source

All Articles