1
4

3 回答 3

3

我遇到了完全相同的问题并以这种方式解决了它:

<configSections xdt:Transform="InsertBefore(/configuration/*[1])" />
<configSections xdt:Locator="XPath(/configuration/configSections[last()])">
     do_your_stuff_with_sections_here...
</configSections>
<configSections xdt:Transform="RemoveAll" xdt:Locator="Condition(count(*)=0)" />

第一行无条件地将节点创建为第一个子节点:

<configSections xdt:Transform="InsertBefore(/configuration/*[1])" />

第二行确保您对最后一个 configSections 节点进行了所有编辑,如果它已经存在,则该节点是正确的节点......<br>

<configSections xdt:Locator="XPath(/configuration/configSections[last()])">

在 de configSections 块中进行转换后,输入删除所有空 configSections 节点的命令……(最后一行)

<configSections xdt:Transform="RemoveAll" xdt:Locator="Condition(count(*)=0)" />
于 2019-02-07T13:26:19.523 回答
0

如何在 app.config 中作为第一个孩子插入

您可以利用该属性xdt:Transform="InsertBefore"在该部分中插入一个新元素,但在任何其他元素之前,例如:

<configSections xdt:Transform="InsertBefore(/configuration/*[1])" />

证书:XDT 转换:InsertBefore - 忽略定位器条件

有关更多详细信息,请参阅如何在 NuGet 中使用 XDT - 示例和事实。

希望这可以帮助。

于 2018-08-10T05:55:51.040 回答
-1

我也在寻找解决方案...

<configSections xdt:Transform="Remove" />
<configSections xdt:Transform="InsertBefore(/configuration/*[1])">
于 2019-01-22T15:24:02.407 回答