[我想在xdt:Transform
配置中执行Debug
,但仅当app.debug.config
中的条目的值是某个值时,才说true
以使其简单。例如:
App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="Value.First" value="foo" />
<add key="Value.Second" value="foo" />
<add key="Value.Third" value="foo" />
</appSettings>
</configuration>
App.Debug.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<!--Convenient flag to indicate if transform should happen-->
<add key="Perform.Transform.If.True" value="true" xdt:Transform="Insert" />
<!--Should only happen if the above is true-->
<add key="Value.First" value="bar" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
<add key="Value.Second" value="bar" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
<add key="Value.Third" value="bar" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
</appSettings>
</configuration>
我只希望将键Value.*
设置为Perform.Transform.If.True
才能转换app.config中的所有true
条目。如果它是false
,则什么也不会发生。原因是有时在测试过程中,我们希望快速打开和关闭由配置文件控制的功能。
我已经看到Locator
的选项,例如Match,Conditional,XPath等,但似乎都不允许来自另一个条目的条件。可以使用slowcheetah / xdt转换吗?
好,使用XPath
找到了一种绕行方式:
<add
key="Value.First"
value="bar"
xdt:Transform="Replace"
xdt:Locator="XPath(//appSettings/add[@key='Perform.Transform.If.True' and translate(@value, 'ERTU', 'ertu')='true']/../add[@key='Value.First'])"
/>
如果标志不是true
,将无法解析路径。 translate
使其不区分大小写。
这会导致令人讨厌的编译警告,但由于这是调试费用,因此我们可以忍受。