Web.config转换移动名称空间声明

Bra*_*AGr 5 c# xml web-config nlog

使用此在线测试仪,很容易看到以下问题

我有一个web.config看起来像:

<?xml version="1.0"?>
<configuration>
  <nlog/>
</configuration>
Run Code Online (Sandbox Code Playgroud)

转换如下所示:

<?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>
Run Code Online (Sandbox Code Playgroud)

但是输出不是我期望的结果,它将xsi名称空间声明下移到使用它的元素,这将导致nlog无法解析带有错误的配置 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>
Run Code Online (Sandbox Code Playgroud)

是否可以使用某种转换选项或语法来防止其移动名称空间声明?我在文档中找不到任何内容

xum*_*mix 1

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