且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

解决方案配置,发布配置文件和web.config转换之间的关系

更新时间:2022-11-05 11:06:38

运行Develop publish配置文件时为何删除<appSettings/>元素的答案是因为两个转换按以下顺序运行.

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.之所以运行该命令,是因为Develop.pubxml文件中的配置目标是Release构建配置.
  2. Web.Develop.config.之所以运行该命令,是因为发布配置文件(开发)的名称与转换文件的名称匹配.

发生的是,第一个转换删除了<appSettings/>元素.第二个转换尝试在该元素中设置键值,但找不到它,因此它默默地失败了.

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.

我能够通过搜索控制台输出来确认这一点.运行Develop转换时,有一条警告,指出找不到所需的元素.

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)

特定于配置文件的web.config转换和转换预览赛义德·易卜拉欣·哈希米(Sayed Ibrahim Hashimi)撰写的文章对确定这一问题非常有帮助.

The Profile specific web.config transforms and transform preview article by Sayed Ibrahim Hashimi was very helpful in identifying this was the issue.

就构建配置,发布配置文件和web.config转换之间的关系而言,我目前的理解是

As far as the relationship between the build configuration, publish profiles, and web.config transform go my current understanding is this.

  1. 发布配置文件具有(除其他外)配置目标
  2. 发布配置文件首先运行转换,该转换将映射到其指定的配置目标名称(如果存在)
  3. 发布配置文件,然后运行转换(如果存在的话)映射到其发布配置文件名称

关键是可以运行两个 web.config转换.

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