简体   繁体   中英

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

将您的xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"声明移动到最顶层的元素,它应该没问题

In my case instead of

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

I had to use

xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM