是否有 NAnt 任务将显示所有属性名称/值?

发布于 2024-07-06 01:37:53 字数 159 浏览 9 评论 0原文

是否有一个 NAnt 任务会回显当前在构建过程中设置的所有属性名称和值? 也许相当于 Ant echoproperties 任务?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

靖瑶 2024-07-13 01:37:55

我尝试了 Brad C 建议的解决方案,但它们对我不起作用(在 x64 上使用 NAnt 0.92 运行 Windows 7 Profession)。 但是,这适用于我的本地配置:

<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>

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>
沒落の蓅哖 2024-07-13 01:37:55

你无法证明是否定的,但我找不到,也没有见过。 我传统上会滚动我自己的财产回声。

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.

Saygoodbye 2024-07-13 01:37:55

我希望对它们进行排序,所以我扩展了另一个答案。 它不是很有效,但它有效:

<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 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>
梦旅人picnic 2024-07-13 01:37:53

试试这个片段:

<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>

你可以保存并使用 nant 运行。

不,还没有任务或功能可以为您执行此操作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文