NANT构建脚本如果条件,

时间:2009-07-24 07:37:28

标签: build nant

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

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

有没有办法实现这个?

提前谢谢, Sidhartha的

1 个答案:

答案 0 :(得分:0)

在您的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文件具有给定命名空间的节点,那么这将无效。