【问题标题】:Web Config Transformation to add a child elementWeb Config 转换以添加子元素
【发布时间】:2012-06-17 11:20:35
【问题描述】:

我在 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 元素的子元素(有效地取消对上述内容的注释)?

我熟悉如何进行基本转换,但以前从未这样做过。

【问题讨论】:

    标签: asp.net web-config web-config-transform


    【解决方案1】:

    您可以使用Insert 转换:

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

    Web.config Transformation Syntax for Web Application Project Deployment

    【讨论】:

      【解决方案2】:

      如果您想使用 XSLT 来实现,那么这里有一些指导,因为我现在没有时间来解决这个问题。

      1. 查找恒等变换。这将为您提供一个简单的 XSLT,它可以准确地复制所读取的内容。
      2. 在通用模板上方添加一个模板,匹配以下match="add[@name='MvcRoutingShim']"
      3. 在模板中使用xsl:copy 输出您正在处理的元素,然后输出AzureReader add 元素

      这应该会让你继续前进。

      确保您有一个允许您进行转换的 XML 编辑器,以便您可以在本地进行试验,直到正确为止。

      【讨论】:

        猜你喜欢
        • 2015-03-30
        • 1970-01-01
        • 1970-01-01
        • 2022-01-13
        • 1970-01-01
        • 2012-06-14
        • 1970-01-01
        • 2019-11-15
        • 1970-01-01
        相关资源
        最近更新 更多