8

NAnt ビルド中にユーザーに入力を促す方法はありますか? パスワードを受け取るコマンドを実行したいのですが、パスワードをビルド スクリプトに入れたくありません。

4

4 に答える 4

8

今のところスクリプトを使用していますが、事前に作成されたメソッドが既に利用可能であるかどうかを知りたいです. ForegroundColor トリックを提供してくれた sundar に感謝します。

Project.Log を使用するか、Console.WriteLine() に直接アクセスするかが重要かどうかはわかりません。

スクリプトとそれを使用するサンプル ターゲットを次に示します。

<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>
于 2008-11-17T23:00:36.010 に答える
6

私が何度も使用した解決策は、各開発者に固有のパスワード、接続文字列などを含むローカル構成ファイルを用意することです。NAnt ビルド スクリプトには、ビルド時にこれらの設定が含まれます。

ローカル構成ファイルはバージョン管理システムに存在しないため、パスワードは公開されません。開発者が初めてコード ベースをチェックアウトしてビルドを試みるとき、この構成ファイルを作成する必要があります。簡単にするために、カスタマイズ可能なすべてのプロパティを含む my.config.template などのテンプレート ファイルを利用できます。

于 2008-11-17T22:20:30.723 に答える
4

これにより、パスワードを入力するとアスタリスクが表示されます。

    <code><![CDATA[
        [Function("ask")]
        public string AskPassword(string prompt) {
            Project.Log(Level.Info, prompt);
            string password = "";

            // get the first character of the password
            ConsoleKeyInfo nextKey = Console.ReadKey(true);

            while (nextKey.Key != ConsoleKey.Enter)
            {
                if (nextKey.Key == ConsoleKey.Backspace)
                {
                    if (password.Length > 0)
                    {
                        password = password.Substring(0, password.Length - 1);

                        // erase the last * as well
                        Console.Write(nextKey.KeyChar);
                        Console.Write(" ");
                        Console.Write(nextKey.KeyChar);
                    }
                }
                else
                {
                    password += nextKey.KeyChar;
                    Console.Write("*");
                }

                nextKey = Console.ReadKey(true);
            }

            Console.WriteLine();

            return password;
        }
    ]]></code>
于 2010-03-30T10:58:11.683 に答える
4

これを試して :

<script language="C#" prefix="test" >
          <code>
            <![CDATA[
              [Function("get-password")]
              public static string GetPassword(  ) {
                  Console.WriteLine("Please enter the password");
                  ConsoleColor oldForegroundColor = Console.ForegroundColor;           
             Console.ForegroundColor = Console.BackgroundColor;
                  string password = Console.ReadLine();
             Console.ForegroundColor = oldForegroundColor;
        return password;
              }
            ]]>
          </code>
</script>

<target name="test.password">
 <echo message='${test::get-password()}'/>
</target>

-->
于 2008-11-17T22:29:36.773 に答える