从代码开始Nant

本文关键字:Nant 开始 代码 | 更新日期: 2023-09-27 17:52:36

我正在尝试使用c#代码启动Nant。在命令行中输入相同的字符串可以正常工作,但在代码中无法工作。下面是我使用的代码

StringWriter consoleOut = new StringWriter( );
Console.SetOut( consoleOut );
ConsoleDriver.Main( new string[] { "-buildfile:" + filePath });

我正在使用nant。核心构建外部文件,但它不会工作…如果我在cmd中使用相同的命令,一切都很顺利…从代码中启动它,我得到以下消息

{NAnt 0.91 (Build 0.91.3881.0;alpha2;版权所有(C) 2001-2010 Gerry肖' r ' nhttp://nant.sourceforge.net ' r ' n ' r ' n ' r ' nFor有关原因的更多信息生成失败时,运行生成还是在调试模式下。' r ' n ' r ' nTry nant-help'获取更多信息'r'n}

从代码开始Nant

您可以向通常从命令行调用的可执行文件进行shell:

            var startInfo = new ProcessStartInfo( executable, parameters )
            {
                UseShellExecute = false,
                RedirectStandardError = false,
                RedirectStandardOutput = false,
                CreateNoWindow = true
            };
            using( var process = Process.Start( startInfo ) )
            {
                if( process != null )
                {
                    process.WaitForExit( timeoutInMilliSeconds );
                    return process.ExitCode;
                }
            }