2008-09-26 291 views

回答

22

试试这个片断:

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

你可以只保存和恶性运行。

不,没有任何功能可以为您做到这一点。

+0

这很漂亮。干杯。 – serg10 2008-09-29 20:32:06

1

你不能证明一个否定的,但我找不到一个,并没有看到一个。我传统上推出了自己的财产回应。

6

我希望他们排序,所以我扩大了另一个答案。这不是很有效的,但是它的工作原理:

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

我试图通过布拉德ç提出的解决方案,但他们并没有为我工作(在x64运行Windows 7专业与恶性0.92)。但是,这适用于我的本地配置:

<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> 
相关问题