目前,我正在创作新的NuGet包,但我不能得到app.config.install.xdt文件正确(这是转变的app.config以适应安装包中的XML文件)。
问题是将在<configSections>中的app.config为第一子部分 - 但只有在情况下,它消失了!
它必须是第一个孩子,或者应用程序将失败,一个异常(微软执行)。
如果我只是用常规的“InsertIfMissing”改造,插入发生任何现有照看孩子,所以这似乎不走。
我能做些什么来解决我的问题呢?
我有完全相同的问题,解决这样说:
<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节点,如果它已经存在这是去正确的节点?
<configSections xdt:Locator="XPath(/configuration/configSections[last()])">
您在德configSections块做变换后,输入(最后一行)的命令删除所有空configSections节点...
<configSections xdt:Transform="RemoveAll" xdt:Locator="Condition(count(*)=0)" />
如何插入在app.config中的第一个孩子
您可以利用属性xdt:Transform="InsertBefore"
的部分,但前插入一个新元素的任何其他元素,如:
<configSections xdt:Transform="InsertBefore(/configuration/*[1])" />
证书:XDT Transform: InsertBefore - Locator Condition is ignored
而看到How to use XDT in NuGet - Examples and Facts一些更多的细节。
希望这可以帮助。
我一直在寻找解决方案,以及...
<configSections xdt:Transform="Remove" />
<configSections xdt:Transform="InsertBefore(/configuration/*[1])">