Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web.config transform Insert as first child

Tags:

asp.net

xslt

When transforming the web.config, how do I insert a web.config node as the first child of the parent? So I have

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Foo" stopProcessing="true">
          ...
        </rule>
        <rule name="Bar" stopProcessing="true">
          ...
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

And I want to insert another rule as the first rule. The below code from web.Release.config only adds it to the end.

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Blah" stopProcessing="true" xdt:Transform="Insert">
         ...
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
like image 697
nthpixel Avatar asked Jun 11 '15 18:06

nthpixel


1 Answers

This did the trick

<rule name="Blah" stopProcessing="true" 
    xdt:Transform="InsertBefore(/configuration/system.webServer/rewrite/rules/rule)">
  ...
</rule>
like image 174
nthpixel Avatar answered Oct 17 '22 14:10

nthpixel