通过 Web 配置转换添加子元素

我在 web.config 中得到了以下配置:

  <resizer>
<sizelimits imageWidth="0" />
<plugins>
<add name="MvcRoutingShim" />
<!--<add name="AzureReader" connectionString="DataConnectionString" /> -->
<add name="DiskCache" />
<add name="PrettyGifs" />
<add name="AnimatedGifs" />
</plugins>
</resizer>

在 web.config 中。Release,我如何添加 AzureReader 元素作为 plugins 元素的子元素(有效地取消上面的注释) ?

我很熟悉如何进行基本的转换,但是以前从来没有这样做过。

37120 次浏览

If you want to do it using XSLT then here is some guidance as I don't have time right now to knock this out.

  1. Look up the identity transform. That will give you a simple XSLT that duplicates exactly what reads.
  2. Add a template above the generic templates with the following match match="add[@name='MvcRoutingShim']"
  3. Inside the template output the element you are processing using xsl:copy and then output the AzureReader add element

That should get you going.

Make sure you have an XML editor that allow you to do transforms so you can experiment locally until you get it right.

You can use the Insert transformation:

 <resizer>
<plugins>
<add name="AzureReader" connectionString="DataConnectionString"
xdt:Transform="Insert" />
</plugins>
</resizer>

Web.config Transformation Syntax for Web Application Project Deployment