我正在尝试使用 C# 代码启动 Nant。在命令行中输入的相同字符串可以正常工作,但在代码中则不起作用。这是我正在使用的代码
StringWriter consoleOut = new StringWriter( );
Console.SetOut( consoleOut );
ConsoleDriver.Main( new string[] { "-buildfile:" + filePath });
我正在使用 nant.core 来构建外部文件,但它不起作用...如果我在 cmd 中使用相同的命令,一切都会顺利...从代码启动它,我收到以下消息
{NAnt 0.91 (Build 0.91.3881.0; alpha2; 17.08.2010.)\r\nCopyright ( C) 2001-2010 Gerry Shaw\r\nhttp://nant.sourceforge.net\r\n\r\n\r\nFor more information regarding the cause of the build failure, run the build again in debug mode.\r\n\r\nTry 'nant -help' for more information\r\n}
也在看 -help 但没有发现任何有用的东西:(
最佳答案
您可以将通常从命令行调用的可执行文件 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;
}
}
关于c# - 从代码启动 Nant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5773601/