仅当app.debug.config中的标志为true时,才转换app.config条目

问题描述 投票:1回答:1

[我想在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转换吗?

visual-studio config app-config slowcheetah xdt-transform
1个回答
0
投票

好,使用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使其不区分大小写。

这会导致令人讨厌的编译警告,但由于这是调试费用,因此我们可以忍受。

© www.soinside.com 2019 - 2024. All rights reserved.