static int Main(string[] argsRaw) { int errors = 0; ArgumentList arguments = new ArgumentList(argsRaw); if (!arguments.Contains("nologo")) { Console.WriteLine("{0}", typeof(Program).Assembly); foreach (System.Reflection.AssemblyCopyrightAttribute a in typeof(Program).Assembly.GetCustomAttributes(typeof(System.Reflection.AssemblyCopyrightAttribute), false)) { Console.WriteLine("{0}", a.Copyright); } Console.WriteLine(".NET Runtime Version={0}", System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion()); } if (arguments.Contains("?") || arguments.Contains("help")) { return(ShowHelp(Console.Out)); } Log.Open(TextWriter.Null); Log.ConsoleLevel = arguments.Contains("verbose") ? TraceLevel.Verbose : TraceLevel.Warning; try { CSBuildConfig config = null; if (arguments.Contains("config")) { using (System.Xml.XmlReader rdr = new System.Xml.XmlTextReader(arguments["config"])) config = Config.ReadXml(Config.SCHEMA_NAME, rdr); } else { config = Config.ReadConfig("CSBuildConfig"); } if (config == null) { throw new ApplicationException("Unable to locate configuration section 'CSBuildConfig', and no /config= option was given."); } string logfile = config.Options.LogPath(new Dictionary <string, string>()); if (arguments.Contains("log")) { logfile = Path.GetFullPath(arguments["log"]); } if (logfile != null) { Directory.CreateDirectory(Path.GetDirectoryName(logfile)); Log.Open(TextWriter.Synchronized(new StreamWriter(File.Open(logfile, FileMode.Create, FileAccess.Write, FileShare.Read | FileShare.Delete)))); if (config.Options.ConsoleEnabled) { Log.ConsoleLevel = arguments.Contains("verbose") ? TraceLevel.Verbose : !arguments.Contains("quiet") ? TraceLevel.Info : TraceLevel.Warning; } } List <string> propertySets = new List <string>(); foreach (BuildProperty p in config.Options.GlobalProperties) { propertySets.Add(String.Format("{0}={1}", p.Name, p.Value)); } if (config.Options.ImportOptionsFile != null) { try { string fpath = config.Options.ImportOptionsFile.AbsolutePath(new Dictionary <string, string>()); propertySets.AddRange(File.ReadAllLines(fpath)); } catch (FileNotFoundException e) { throw new ApplicationException("Unable to locate options file: " + e.FileName, e); } } propertySets.AddRange(arguments.SafeGet("p").Values); propertySets.AddRange(arguments.SafeGet("property").Values); using (Log.AppStart(Environment.CommandLine)) using (Log.Start("Build started {0}", DateTime.Now)) { LoggerVerbosity?verbosity = config.Options.ConsoleLevel; if (arguments.Contains("quiet")) { verbosity = LoggerVerbosity.Quiet; } else if (arguments.Contains("verbose")) { verbosity = LoggerVerbosity.Normal; } else if (arguments.Contains("verbosity")) { verbosity = (LoggerVerbosity)Enum.Parse(typeof(LoggerVerbosity), arguments["verbosity"], true); } string[] targetNames = new List <string>(arguments.Unnamed).ToArray(); using (CmdLineBuilder b = new CmdLineBuilder(config, verbosity, arguments.SafeGet("group"), targetNames, propertySets.ToArray())) { b.Start(); errors += b.Complete(TimeSpan.FromHours(config.Options.TimeoutHours)); } } } catch (ApplicationException ae) { Log.Verbose(ae.ToString()); Log.Error("\r\n{0}", ae.Message); errors += 1; } catch (System.Configuration.ConfigurationException ce) { Log.Verbose(ce.ToString()); Log.Error("\r\nConfiguration Exception: {0}", ce.Message); errors += 1; } catch (Exception e) { Log.Error(e); errors += 1; } if (arguments.Contains("wait")) { Console.WriteLine(); Console.WriteLine("Press [Enter] to continue..."); Console.ReadLine(); } return(errors); }
static int Main(string[] argsRaw) { int errors = 0; ArgumentList arguments = new ArgumentList(argsRaw); if (!arguments.Contains("nologo")) { Console.WriteLine("{0}", typeof (Program).Assembly); foreach (System.Reflection.AssemblyCopyrightAttribute a in typeof(Program).Assembly.GetCustomAttributes(typeof(System.Reflection.AssemblyCopyrightAttribute), false)) Console.WriteLine("{0}", a.Copyright); Console.WriteLine(".NET Runtime Version={0}", System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion()); } if (arguments.Contains("?") || arguments.Contains("help")) return ShowHelp(Console.Out); Log.Open(TextWriter.Null); Log.ConsoleLevel = arguments.Contains("verbose") ? TraceLevel.Verbose : TraceLevel.Warning; try { CSBuildConfig config = null; if (arguments.Contains("config")) { using (System.Xml.XmlReader rdr = new System.Xml.XmlTextReader(arguments["config"])) config = Config.ReadXml(Config.SCHEMA_NAME, rdr); } else config = Config.ReadConfig("CSBuildConfig"); if (config == null) throw new ApplicationException("Unable to locate configuration section 'CSBuildConfig', and no /config= option was given."); string logfile = config.Options.LogPath(new Dictionary<string, string>()); if (arguments.Contains("log")) logfile = Path.GetFullPath(arguments["log"]); if (logfile != null) { Directory.CreateDirectory(Path.GetDirectoryName(logfile)); Log.Open(TextWriter.Synchronized(new StreamWriter(File.Open(logfile, FileMode.Create, FileAccess.Write, FileShare.Read | FileShare.Delete)))); if(config.Options.ConsoleEnabled) Log.ConsoleLevel = arguments.Contains("verbose") ? TraceLevel.Verbose : !arguments.Contains("quiet") ? TraceLevel.Info : TraceLevel.Warning; } List<string> propertySets = new List<string>(); foreach (BuildProperty p in config.Options.GlobalProperties) propertySets.Add(String.Format("{0}={1}",p.Name, p.Value)); if (config.Options.ImportOptionsFile != null) { try { string fpath = config.Options.ImportOptionsFile.AbsolutePath(new Dictionary<string, string>()); propertySets.AddRange(File.ReadAllLines(fpath)); } catch(FileNotFoundException e) { throw new ApplicationException("Unable to locate options file: " + e.FileName, e); } } propertySets.AddRange(arguments.SafeGet("p").Values); propertySets.AddRange(arguments.SafeGet("property").Values); using (Log.AppStart(Environment.CommandLine)) using (Log.Start("Build started {0}", DateTime.Now)) { LoggerVerbosity? verbosity = config.Options.ConsoleLevel; if (arguments.Contains("quiet")) verbosity = LoggerVerbosity.Quiet; else if (arguments.Contains("verbose")) verbosity = LoggerVerbosity.Normal; else if (arguments.Contains("verbosity")) verbosity = (LoggerVerbosity)Enum.Parse(typeof(LoggerVerbosity), arguments["verbosity"], true); string[] targetNames = new List<string>(arguments.Unnamed).ToArray(); using (CmdLineBuilder b = new CmdLineBuilder(config, verbosity, arguments.SafeGet("group"), targetNames, propertySets.ToArray())) { b.Start(); errors += b.Complete(TimeSpan.FromHours(config.Options.TimeoutHours)); } } } catch (ApplicationException ae) { Log.Verbose(ae.ToString()); Log.Error("\r\n{0}", ae.Message); errors += 1; } catch (System.Configuration.ConfigurationException ce) { Log.Verbose(ce.ToString()); Log.Error("\r\nConfiguration Exception: {0}", ce.Message); errors += 1; } catch (Exception e) { Log.Error(e); errors += 1; } if (arguments.Contains("wait")) { Console.WriteLine(); Console.WriteLine("Press [Enter] to continue..."); Console.ReadLine(); } return errors; }