Web Config Transformation to add a child element

asp.netWeb ConfigWeb Config-Transform

asp.net Problem Overview


I've got the following configuration in 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>

In web.config.Release, how can I add the AzureReader element as a child of the plugins element (effectively uncommenting out the above)?

I'm familiar with how to do basic transformations but have never done this before.

asp.net Solutions


Solution 1 - asp.net

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

Solution 2 - asp.net

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBen FosterView Question on Stackoverflow
Solution 1 - asp.netjrummellView Answer on Stackoverflow
Solution 2 - asp.netJim KeeneyView Answer on Stackoverflow