【问题标题】:Case insensitive match locator config transformation不区分大小写的匹配定位器配置转换
【发布时间】:2019-10-22 22:42:35
【问题描述】:

我正在根据环境转换 web.config 文件中 appsettings 的值。当键名相同但大小写不同时,我遇到了一个问题,示例如下

本地价值

<add xdt:Transform="RemoveAll" xdt:Locator="Match(key)" key="LOGINURL" value="xyf" />

开发价值

<add xdt:Transform="RemoveAll" xdt:Locator="Match(key)" key="LoginUrl" value="abcd" />

我想不区分大小写地替换键的值。

TIA

【问题讨论】:

    标签: c# web-config web.config-transform


    【解决方案1】:

    您可以将XPaththe Condition locator 一起使用,而不是Match。 并且使用here on building case insensitive matching in XPath 描述的hack,您也许可以这样写:

    <add xdt:Transform="RemoveAll" xdt:Locator= "Condition(translate(@key,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='loginurl')"/>
    

    keyvalue 属性无用,因为元素已被删除。

    要编辑元素,请使用SetAttributes 以保持键不变。

    <add xdt:Transform="SetAttributes" xdt:Locator="Condition(translate(@key,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='loginurl')" value="test.com" />
    

    我测试了所有here

    【讨论】:

    • 我还在寻找 XPath2
    • 这不适用于 Microsoft 转换 DLL :(
    • @Chakri 你确定吗?我在VS2019中测试过,它可以工作。转换仅在发布时可见,请参阅:stackoverflow.com/questions/8841075。请使用转换预览(右键单击 Web.Debug.config 文件 -> 预览转换)。
    猜你喜欢
    • 2013-10-19
    • 1970-01-01
    • 2012-03-01
    • 1970-01-01
    • 2017-11-14
    • 2012-03-15
    • 1970-01-01
    • 2022-06-13
    • 1970-01-01
    相关资源
    最近更新 更多