Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a NAnt task that will display all property name / values?

Is there a NAnt task that will echo out all property names and values that are currently set during a build? Something equivalent to the Ant echoproperties task maybe?

like image 908
serg10 Avatar asked Sep 26 '08 16:09

serg10


2 Answers

Try this snippet:

<project>
    <property name="foo" value="bar"/>
    <property name="fiz" value="buz"/>

    <script language="C#" prefix="util" >
        <code>
            <![CDATA[
            public static void ScriptMain(Project project) 
            {
                foreach (DictionaryEntry entry in project.Properties)
                {
                    Console.WriteLine("{0}={1}", entry.Key, entry.Value);
                }
            }
            ]]>
        </code>
    </script>
</project>

You can just save and run with nant.

And no, there isn't a task or function to do this for you already.

like image 169
craigb Avatar answered Oct 16 '22 14:10

craigb


I tried the solutions suggested by Brad C, but they did not work for me (running Windows 7 Profession on x64 with NAnt 0.92). However, this works for my local configuration:

<target name="echo-properties" verbose="false" description="Echo property values" inheritall="true">
<script language="C#">
    <code>
    <![CDATA[
        public static void ScriptMain(Project project)
        {
        System.Collections.SortedList sortedByKey = new System.Collections.SortedList();
        foreach(DictionaryEntry de in project.Properties)
        {
            sortedByKey.Add(de.Key, de.Value);
        }

        NAnt.Core.Tasks.EchoTask echo = new NAnt.Core.Tasks.EchoTask();
        echo.Project = project;

        foreach(DictionaryEntry de in sortedByKey)
        {
            if(de.Key.ToString().StartsWith("nant."))
            {
                continue;
            }
            echo.Message = String.Format("{0}: {1}", de.Key,de.Value);
            echo.Execute();
        }
        }
    ]]>
    </code>
</script>
</target>
like image 44
Ben Corpus Avatar answered Oct 16 '22 16:10

Ben Corpus