【问题标题】:NANT Build Scripts If Condition,NANT Build Scripts If Condition,
【发布时间】:2009-09-13 23:00:00
【问题描述】:

我有一个关于 Nant 构建脚本的查询,我对 NANT 构建相当陌生,如果我想根据 xml 文件中的某些条件运行样式,请说

count(${skinFolder}/screens.temp.xml//ActionCollection/Item) > 0

有没有办法做到这一点??

提前致谢, 悉达多

【问题讨论】:

    标签: build nant


    【解决方案1】:

    在您的 NAnt 脚本的 project 节点下添加以下内容:

    <script language="c#" prefix="custom">
        <code>
            <![CDATA[
            [Function("evaluate-xpath")]
            public static string EvaluateXPath(string xpath, string info)
            {
            System.Xml.XPath.XPathDocument xml = new System.Xml.XPath.XPathDocument(info);
            return xml.CreateNavigator().Evaluate(xpath).ToString();
            }
            ]]>
        </code>
    </script>
    

    那么你可以使用下面的表达式来实现你想要的:

    if="${int::parse(custom::evaluate-xpath('count(//ActionCollection/Item)', path::combine(skinFolder 'screens.temp.xml'))) &gt; 0}"
    

    请注意,如果您的 xml 文件具有指定命名空间的节点,那么这将不起作用。

    【讨论】:

      猜你喜欢
      • 2013-11-18
      • 1970-01-01
      • 2013-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-11
      相关资源
      最近更新 更多