c# - 从代码启动 Nant

标签 c# build nant

我正在尝试使用 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/

相关文章:

java - Intellij Idea java构建生产失败: java. lang.ClassCastException

javascript - Angular如何引用dist中的图片资源

android - 任务 ':app:mergeDebugResources' 的 Flutter 构建失败

nant - 从 NANT 更改命令 (CMD) 窗口的标题

cruisecontrol.net - 如何根据 .NET 代码的输出添加 Cruisecontrol.net 构建步骤

path - NAnt - 如何获取包含脚本的目录路径

c# - 使用 application/octet-stream 进行 POST 调用

c# - 如何将 C# 控制台应用程序附加到正在运行的 Windows 服务?

c# - 反序列化包含与关键字冲突的属性的 JSON 响应

c# - 如何在 WPF 中使用 MVVM 在页面和打开的窗口之间导航?