문제

현재 빌드 중에 설정된 모든 속성 이름과 값을 반영하는 넌트 작업이 있습니까? 개미와 동등한 것 에코 프로 erties 어쩌면 작업?

도움이 되었습니까?

해결책

이 스 니펫을 사용해보십시오.

<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와 함께 저장하고 달릴 수 있습니다.

그리고 아니요, 이미 당신을 위해 이것을하는 과제 나 기능이 없습니다.

다른 팁

나는 그들이 다른 대답을 확장하여 분류를 원했습니다. 그다지 효율적이지는 않지만 작동합니다.

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

당신은 부정적인 것을 증명할 수는 없지만, 나는 하나를 찾을 수없고 그것을 보지 못했습니다. 나는 전통적으로 내 자신의 재산 에코를 굴 렸습니다.

나는 Brad C가 제안한 솔루션을 시도했지만 나에게는 효과가 없었습니다 (NANT 0.92로 X64에서 Windows 7 직업을 실행). 그러나 이것은 내 로컬 구성에 적합합니다.

<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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top