public static CommandLineResults ExecuteCommand(string command, string workingDirectory, string arguments)
        {
            try {
            // Build our ProcessStartInfo
            ProcessStartInfo psi = new ProcessStartInfo (command, arguments);

            if (!string.IsNullOrEmpty (workingDirectory))
                psi.WorkingDirectory = workingDirectory;

            // Set up output buffers
            StringBuilder std_output = new StringBuilder ();
            StringBuilder std_error = new StringBuilder ();

            psi.RedirectStandardOutput = true;
            psi.RedirectStandardError = true;

            psi.UseShellExecute = false;

            Process p = new Process ();
            p.StartInfo = psi;

            p.OutputDataReceived += delegate (object sender, DataReceivedEventArgs e) {
                std_output.AppendLine (e.Data);
            };

            p.ErrorDataReceived += delegate (object sender, DataReceivedEventArgs e) {
                std_error.AppendLine (e.Data);
            };

            // Run our Process
            DateTime start = DateTime.Now;

            p.Start ();
            p.BeginOutputReadLine();
            p.BeginErrorReadLine();

            p.WaitForExit ();

            CommandLineResults results = new CommandLineResults ();

            results.ExecutionTime = DateTime.Now.Subtract (start);
            results.ExitCode = p.ExitCode;

            // Robocopy has "success" exitcodes 0-7  :(
            if (command.ToLowerInvariant () == "robocopy" && p.ExitCode < 8)
                results.ExitCode = 0;

            results.Output = std_output.ToString ();
            results.ErrorOutput = std_error.ToString ();

            return results;
            } catch (Win32Exception ex) {
                Console.WriteLine ("Cannot find file:");
                Console.WriteLine ("Command: {0}", command);

                throw;
            }
        }
Exemple #2
0
        public override void Execute(XmlElement config)
        {
            string assembly  = Utilities.ReplaceArgs(config.InnerText, Revision);
            string tool_path = Utilities.CombinePaths(Environment.CurrentDirectory, "build", "lib", "mono", "2.0", "gacutil.exe");
            string mono_path = Utilities.CombinePaths(Environment.CurrentDirectory, "build", "bin", "mono.exe");

            string args = string.Format("\"{0}\" -i \"{1}\"", tool_path, assembly);

            CommandLineResults results = CommandLineRunner.ExecuteCommand(mono_path, null, args);

            if (results.ExitCode == 0)
            {
                File.Delete(assembly + ".mdb");
            }
        }
Exemple #3
0
        public override void Execute(XmlElement config)
        {
            string tool_path   = Utilities.CombinePaths(Environment.CurrentDirectory, "build", "lib", "mono", "2.0", "gmcs.exe");
            string mono_path   = Utilities.CombinePaths(Environment.CurrentDirectory, "build", "bin", "mono.exe");
            string output_path = Utilities.ReplaceArgs(config.GetAttribute("destination"), Revision);

            if (config.GetAttribute("mono") == "install")
            {
                tool_path = Utilities.CombinePaths(Settings.Default.installedmono, "lib", "mono", "2.0", "gmcs.exe");
                mono_path = Utilities.CombinePaths(Settings.Default.installedmono, "bin", "mono.exe");
            }

            Log.AppendFormat("Building: {0}\n", config.GetAttribute("name"));
            Console.WriteLine("Building: {0}", config.GetAttribute("name"));

            if (!Directory.Exists(Path.GetDirectoryName(output_path)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(output_path));
            }

            string args = string.Empty;

            args  = string.Format("\"{0}\"", tool_path);
            args += " /codepage:65001 -optimize";

            //args += " -d:" + profile_defines;

            if (config["DefineConstants"] != null)
            {
                args += " -d:" + config["DefineConstants"].InnerText;
            }
            if (config["AllowUnsafeBlocks"] != null)
            {
                args += " -unsafe";
            }
            if (config["OutputType"] != null)
            {
                args += " -target:" + config["OutputType"].InnerText;
            }
            if (config["IgnoreWarnings"] != null)
            {
                args += " -nowarn:" + config["IgnoreWarnings"].InnerText;
            }
            if (config["Debug"] == null || config["Debug"].InnerText == "true")
            {
                args += " -debug";
            }
            if (config["NoConfig"] == null || config["NoConfig"].InnerText == "true")
            {
                args += " -noconfig";
            }
            if (config["NoStandardLib"] != null && config["NoStandardLib"].InnerText == "true")
            {
                args += " -nostdlib";
            }
            if (config["KeyFile"] != null)
            {
                args += string.Format(" -keyfile:{0}", Utilities.ReplaceArgs(config["KeyFile"].InnerText, Revision));
            }

            foreach (XmlElement reference in config.SelectNodes("References/Reference"))
            {
                if (!string.IsNullOrEmpty(reference.GetAttribute("alias")))
                {
                    args += string.Format(" -r:{0}={1}", reference.GetAttribute("alias"), reference.InnerText);
                }
                else
                {
                    args += " -r:" + reference.InnerText;
                }
            }

            args += string.Format(" -out:{0}", output_path);

            foreach (XmlElement sourcenode in config.SelectNodes("Sources/Source"))
            {
                if (sourcenode.GetAttribute("type") == "list")
                {
                    args += " @" + sourcenode.InnerText;
                }
                else
                {
                    args += " " + sourcenode.InnerText;
                }
            }

            string working_path = Utilities.ReplaceArgs(config["SourcePath"].InnerText, Revision);

            CommandLineResults results = CommandLineRunner.ExecuteCommand(mono_path, working_path, args);

            Log.AppendLine(results.Output);

            if (results.ExitCode != 0)
            {
                Log.AppendFormat("BuildTask returned: {0}\n\n--- Error Log ---\n", results.ExitCode);
                Log.AppendLine(results.ErrorOutput);
                Console.WriteLine("Build Failed");
                Console.WriteLine(results.ErrorOutput);
                throw new ApplicationException(string.Format("BuildTask returned: {0}", results.ExitCode));
            }
        }
Exemple #4
0
        public static CommandLineResults ExecuteCommand(string command, string workingDirectory, string arguments)
        {
            try {
                // Build our ProcessStartInfo
                ProcessStartInfo psi = new ProcessStartInfo(command, arguments);

                if (!string.IsNullOrEmpty(workingDirectory))
                {
                    psi.WorkingDirectory = workingDirectory;
                }

                // Set up output buffers
                StringBuilder std_output = new StringBuilder();
                StringBuilder std_error  = new StringBuilder();

                psi.RedirectStandardOutput = true;
                psi.RedirectStandardError  = true;

                psi.UseShellExecute = false;

                Process p = new Process();
                p.StartInfo = psi;

                p.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) {
                    std_output.AppendLine(e.Data);
                };

                p.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e) {
                    std_error.AppendLine(e.Data);
                };

                // Run our Process
                DateTime start = DateTime.Now;

                p.Start();
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();

                p.WaitForExit();

                CommandLineResults results = new CommandLineResults();

                results.ExecutionTime = DateTime.Now.Subtract(start);
                results.ExitCode      = p.ExitCode;

                // Robocopy has "success" exitcodes 0-7  :(
                if (command.ToLowerInvariant() == "robocopy" && p.ExitCode < 8)
                {
                    results.ExitCode = 0;
                }

                results.Output      = std_output.ToString();
                results.ErrorOutput = std_error.ToString();

                return(results);
            } catch (Win32Exception ex) {
                Console.WriteLine("Cannot find file:");
                Console.WriteLine("Command: {0}", command);

                throw;
            }
        }