Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web.config transform moving namespace declaration

Using this online tester it is easy to see the following issue

I have a web.config that looks like:

<?xml version="1.0"?>
<configuration>
  <nlog/>
</configuration>

And a transform that looks like:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <xdt:Import assembly="AppHarbor.TransformTester" namespace="AppHarbor.TransformTester.Transforms"/>

  <nlog xdt:Transform="Replace"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <targets async="true">
      <target name="LogMill" xsi:type="FallbackGroup" returnToFirstOnSuccess="true">
        <target xsi:type="LogMillMessageBus"/>
        <target xsi:type="File" fileName="..\LogMill-FailSafe.log" layout="${TextErrorLayout}"/>
      </target>
    </targets>
  </nlog>
</configuration>

But the output is not what I expect, it moves the xsi namespace declaration down to the element that uses it, which causes nlog to fail to parse the configuration with the error Parameter p4 not supported on FallbackGroupTarget

<?xml version="1.0"?>
<configuration>
  <nlog>
    <targets async="true">
      <target name="LogMill" p4:type="FallbackGroup" returnToFirstOnSuccess="true" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">
      <target p4:type="LogMillMessageBus" /><target p4:type="File" fileName="..\LogMill-FailSafe.log" layout="${TextErrorLayout}" />
      </target>
    </targets>
  </nlog>
</configuration>

Is there a transform option or syntax that I can apply to prevent it from moving the namespace declaration? I couldn't find anything in the documentation

like image 663
BrandonAGr Avatar asked Feb 02 '14 23:02

BrandonAGr


1 Answers

Move your xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" declaration to the topmost element and it should be OK

like image 161
xumix Avatar answered Sep 22 '22 20:09

xumix