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

c# – 如果没有子节点,则清除xdt元素

发布时间:2020-12-15 08:46:23 所属栏目:百科 来源:网络整理
导读:所以我开始玩nuget,它是web.config install / uninstall.xdt值. 我的问题是,是否存在xdt:Transform将清除空元素.我在这里找不到任何东西. https://msdn.microsoft.com/en-us/library/dd465326%28v=vs.110%29.aspx 这是我的例子. 我当前的Web.config.install
所以我开始玩nuget,它是web.config install / uninstall.xdt值.

我的问题是,是否存在xdt:Transform将清除空元素.我在这里找不到任何东西.
https://msdn.microsoft.com/en-us/library/dd465326%28v=vs.110%29.aspx

这是我的例子.

我当前的Web.config.install.xdt看起来像这样

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>
    <compilation xdt:Transform="InsertIfMissing">
      <assemblies xdt:Transform="InsertIfMissing">
        <add xdt:Transform="InsertIfMissing" xdt:Locator="Match(assembly)" assembly="MyAssembly,Version=4.5.4.0,Culture=neutral,PublicKeyToken=asdfasdfasdfasdf" />
      </assemblies>
    </compilation>
  </system.web>
</configuration>

我的卸载看起来像这样

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>
    <compilation>
      <assemblies>
        <add xdt:Transform="Remove" xdt:Locator="Match(assembly)" assembly="MyAssembly,PublicKeyToken=asdfasdfasdfasdf" />
      </assemblies>
    </compilation>
  </system.web>
</configuration>

这是我的web.config之前(简化)

<system.web>
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>

这是install.xtd之后的web.config

<system.web>
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.5">
      <assemblies>
        <add assembly="MyAssembly,PublicKeyToken=asdfasdfasdfasdf" />
      </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.5" />
  </system.web>

这是卸载后的web.config

<system.web>
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.5">
      <assemblies>
      </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.5" />
  </system.web>

反正有没有摆脱标签?

解决方法

您似乎可以在元素上指定多个转换.因此,您可以从安装中删除内容,然后检查该元素是否具有子元素,如果不是,则删除该元素.
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>
    <compilation>
      <assemblies>
        <add xdt:Transform="Remove" xdt:Locator="Match(assembly)" assembly="MyAssembly,PublicKeyToken=asdfasdfasdfasdf" />
      </assemblies>
      <assemblies xdt:Locator="Condition(count(*) = 0)" xdt:Transform="Remove"/>
    </compilation>
  </system.web>
</configuration>

(编辑:李大同)

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

    推荐文章
      热点阅读