Dot-Net

在 NAnt 建構腳本中處理密碼

  • March 31, 2010

有沒有辦法在 NAnt 建構期間提示使用者輸入?我想執行一個需要密碼的命令,但我不想將密碼放入建構腳本中。

我現在正在使用腳本,但我很想知道是否有可用的預建構方法。非常感謝 sundar 的 ForegroundColor 技巧。

我不確定您是使用 Project.Log 還是直接訪問 Console.WriteLine() 是否重要,是否有任何 NAnt 忍者想教育我?

這是腳本和使用它的範例目標:

<target name="input">
   <script language="C#" prefix="password" >
       <code><![CDATA[
           [Function("ask")]
           public string AskPassword(string prompt) {
               Project.Log(Level.Info, prompt);
               ConsoleColor oldColor = Console.ForegroundColor;
               Console.ForegroundColor = Console.BackgroundColor;
               try
               {
                   return Console.ReadLine();
               }
               finally
               {
                   Console.ForegroundColor = oldColor;
               }
           }
       ]]></code>
   </script>

   <echo message="Password is ${password::ask('What is the password?')}"/>
</target>

引用自:https://stackoverflow.com/questions/297136