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?
Is there a NAnt task that will display all property name / values?
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.
Still helping after a decade! –
Garrik
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>
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>
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.
© 2022 - 2024 — McMap. All rights reserved.