加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – Web.config转换移动命名空间声明

发布时间:2020-12-15 22:01:01 所属栏目:百科 来源:网络整理
导读:使用 this online tester可以很容易地看到以下问题 我有一个web.config,看起来像: ?xml version="1.0"?configuration nlog//configuration 并且变换看起来像: ?xml version="1.0"?configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Tra
使用 this online tester可以很容易地看到以下问题

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

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

并且变换看起来像:

<?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>

但输出不是我所期望的,它将xsi命名空间声明向下移动到使用它的元素,这导致nlog无法解析配置,并且错误参数p4不支持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>

是否有可以应用的转换选项或语法来阻止它移动命名空间声明?我在the documentation找不到任何东西

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读