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

4

13

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?

Aeroballistics answered 26/9, 2008 at 16:43 Comment(0)
H
25

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.

Hutton answered 26/9, 2008 at 18:36 Comment(1)
Still helping after a decade!Garrik
S
6

I wanted them sorted so I expanded on the other answer. It's not very efficient, but it works:

<script language="C#" prefix="util" >
    <references>
        <include name="System.dll" />
    </references>       
    <imports>
        <import namespace="System.Collections.Generic" />
    </imports>      
    <code>
        <![CDATA[
        public static void ScriptMain(Project project) 
        {
            SortedDictionary<string, string> sorted = new SortedDictionary<string, string>();
            foreach (DictionaryEntry entry in project.Properties){
                sorted.Add((string)entry.Key, (string)entry.Value);
            }
            foreach (KeyValuePair<string, string> entry in sorted)
            {
                project.Log(Level.Info, "{0}={1}", entry.Key, entry.Value);
            }
        }
        ]]>
    </code>
</script>
Sequence answered 7/12, 2012 at 23:22 Comment(0)
S
2

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>
Sparrowgrass answered 27/11, 2013 at 17:4 Comment(0)
V
1

You can't prove a negative, but I can't find one and haven't seen one. I've traditionally rolled my own property echoes.

Vibrio answered 26/9, 2008 at 17:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.