在南特构建脚本的密码处理南特、脚本、密码

2023-09-04 23:55:38 作者:保重千千萬

有没有办法在一个NAnt构建以提示用户输入?我想执行的命令,需要一个密码,但是我不想把密码进入构建脚本。

Is there a way to prompt the user for input during a NAnt build? I want to execute a command that takes a password, but I don't want to put the password into the build script.

推荐答案

我使用的脚本,但我很想听听是否有已有一个prebuilt方法。非常感谢孙大信为ForegroundColor把戏。

I'm using a script for now, but I'd love to hear if there's a prebuilt method already available. Many thanks to sundar for the ForegroundColor trick.

我不知道,如果它的事项是否使用Project.Log,或者直接Console.WriteLine(),任楠忍者想要教育我?

I'm not sure if it matters whether you use Project.Log or go direct to Console.WriteLine(), any NAnt ninjas want to educate me?

下面是使用它的脚本和一个示例目标:

Here's the script and a sample target that uses it:

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