gpt4 book ai didi

c# - 清除没有子元素的 xdt 元素

转载 作者:太空狗 更新时间:2023-10-29 21:22:09 24 4
gpt4 key购买 nike

所以我开始玩 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, Version=4.5.4.0, Culture=neutral, 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, Version=4.5.4.0, Culture=neutral, 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, Version=4.5.4.0, Culture=neutral, PublicKeyToken=asdfasdfasdfasdf" />
</assemblies>
<assemblies xdt:Locator="Condition(count(*) = 0)" xdt:Transform="Remove"/>
</compilation>
</system.web>
</configuration>

关于c# - 清除没有子元素的 xdt 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28592158/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com