Relationship between solution configuration, publish profile, and web.config transforms

我只是一个虾纸丫 提交于 2019-12-03 07:07:39

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.

  1. Web.Release.config. This is run because the configuration target in the Develop.pubxml file is the Release build configuration.
  2. Web.Develop.config. This is run because the name of the publish profile (Develop) matches the name of the transform file.

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.

  1. Publish profiles have (among other things) a configuration target
  2. Publish profiles first run the transformation that maps to the their specified configuration target name if one exists
  3. Publish profiles then run the transformation that maps to their publish profile name if one exists

The key here being that two web.config transformations may be run.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!