コード例 #1
0
        public void Execute()
        {
            bool result          = false;
            bool show_stacktrace = false;

            try {
                parameters.ParseArguments(args);
                show_stacktrace = (parameters.LoggerVerbosity == LoggerVerbosity.Detailed ||
                                   parameters.LoggerVerbosity == LoggerVerbosity.Diagnostic);

                if (!parameters.NoLogo)
                {
                    ErrorUtilities.ShowVersion(false);
                }

                engine = Engine.GlobalEngine;
                if (!String.IsNullOrEmpty(parameters.ToolsVersion))
                {
                    if (engine.Toolsets [parameters.ToolsVersion] == null)
                    {
                        ErrorUtilities.ReportError(0, new UnknownToolsVersionException(parameters.ToolsVersion).Message);
                    }

                    engine.DefaultToolsVersion = parameters.ToolsVersion;
                }

                engine.GlobalProperties = this.parameters.Properties;

                if (!parameters.NoConsoleLogger)
                {
                    printer = new ConsoleReportPrinter();
                    ConsoleLogger cl = new ConsoleLogger(parameters.LoggerVerbosity,
                                                         printer.Print, printer.SetForeground, printer.ResetColor);

                    cl.Parameters = parameters.ConsoleLoggerParameters;
                    cl.Verbosity  = parameters.LoggerVerbosity;
                    engine.RegisterLogger(cl);
                }

                if (parameters.FileLoggerParameters != null)
                {
                    for (int i = 0; i < parameters.FileLoggerParameters.Length; i++)
                    {
                        string fl_params = parameters.FileLoggerParameters [i];
                        if (fl_params == null)
                        {
                            continue;
                        }

                        var fl = new FileLogger();
                        if (fl_params.Length == 0 && i > 0)
                        {
                            fl.Parameters = String.Format("LogFile=msbuild{0}.log", i);
                        }
                        else
                        {
                            fl.Parameters = fl_params;
                        }
                        engine.RegisterLogger(fl);
                    }
                }

                foreach (LoggerInfo li in parameters.Loggers)
                {
                    Assembly assembly;
                    if (li.InfoType == LoadInfoType.AssemblyFilename)
                    {
                        assembly = Assembly.LoadFrom(li.Filename);
                    }
                    else
                    {
                        assembly = Assembly.Load(li.AssemblyName);
                    }
                    ILogger logger = (ILogger)Activator.CreateInstance(assembly.GetType(li.ClassName));
                    logger.Parameters = li.Parameters;
                    engine.RegisterLogger(logger);
                }

                project = engine.CreateNewProject();

                if (parameters.Validate)
                {
                    if (parameters.ValidationSchema == null)
                    {
                        project.SchemaFile = defaultSchema;
                    }
                    else
                    {
                        project.SchemaFile = parameters.ValidationSchema;
                    }
                }

                string projectFile = parameters.ProjectFile;
                if (!File.Exists(projectFile))
                {
                    ErrorUtilities.ReportError(0, String.Format("Project file '{0}' not found.", projectFile));
                    return;
                }

                result = engine.BuildProjectFile(projectFile, parameters.Targets, null, null, BuildSettings.None, parameters.ToolsVersion);
            }

            catch (InvalidProjectFileException ipfe) {
                ErrorUtilities.ReportError(0, show_stacktrace ? ipfe.ToString() : ipfe.Message);
            }

            catch (InternalLoggerException ile) {
                ErrorUtilities.ReportError(0, show_stacktrace ? ile.ToString() : ile.Message);
            }

            catch (CommandLineException cle) {
                ErrorUtilities.ReportError(cle.ErrorCode, show_stacktrace ? cle.ToString() : cle.Message);
            }
            finally {
                if (engine != null)
                {
                    engine.UnregisterAllLoggers();
                }

                Environment.Exit(result ? 0 : 1);
            }
        }
コード例 #2
0
        public void Execute()
        {
            bool result          = false;
            bool show_stacktrace = false;

            try {
                parameters.ParseArguments(args);
                show_stacktrace = (parameters.LoggerVerbosity == LoggerVerbosity.Detailed ||
                                   parameters.LoggerVerbosity == LoggerVerbosity.Diagnostic);

                if (parameters.DisplayVersion)
                {
                    ErrorUtilities.ShowVersion(false);
                }

                engine = new Engine(binPath);

                engine.GlobalProperties = this.parameters.Properties;

                if (!parameters.NoConsoleLogger)
                {
                    printer = new ConsoleReportPrinter();
                    ConsoleLogger cl = new ConsoleLogger(parameters.LoggerVerbosity,
                                                         printer.Print, printer.SetForeground, printer.ResetColor);

                    cl.Parameters = parameters.ConsoleLoggerParameters;
                    cl.Verbosity  = parameters.LoggerVerbosity;
                    engine.RegisterLogger(cl);
                }

                foreach (LoggerInfo li in parameters.Loggers)
                {
                    Assembly assembly;
                    if (li.InfoType == LoadInfoType.AssemblyFilename)
                    {
                        assembly = Assembly.LoadFrom(li.Filename);
                    }
                    else
                    {
                        assembly = Assembly.Load(li.AssemblyName);
                    }
                    ILogger logger = (ILogger)Activator.CreateInstance(assembly.GetType(li.ClassName));
                    logger.Parameters = li.Parameters;
                    engine.RegisterLogger(logger);
                }

                project = engine.CreateNewProject();

                if (parameters.Validate)
                {
                    if (parameters.ValidationSchema == null)
                    {
                        project.SchemaFile = defaultSchema;
                    }
                    else
                    {
                        project.SchemaFile = parameters.ValidationSchema;
                    }
                }

                string projectFile = parameters.ProjectFile;
                if (!File.Exists(projectFile))
                {
                    ErrorUtilities.ReportError(0, String.Format("Project file '{0}' not found.", projectFile));
                    return;
                }

                project.Load(projectFile);

                string oldCurrentDirectory = Environment.CurrentDirectory;
                string dir = Path.GetDirectoryName(projectFile);
                if (!String.IsNullOrEmpty(dir))
                {
                    Directory.SetCurrentDirectory(dir);
                }
                result = engine.BuildProject(project, parameters.Targets, null);
                Directory.SetCurrentDirectory(oldCurrentDirectory);
            }

            catch (InvalidProjectFileException ipfe) {
                ErrorUtilities.ReportError(0, show_stacktrace ? ipfe.ToString() : ipfe.Message);
            }

            catch (InternalLoggerException ile) {
                ErrorUtilities.ReportError(0, show_stacktrace ? ile.ToString() : ile.Message);
            }

            catch (CommandLineException cle) {
                ErrorUtilities.ReportError(cle.ErrorCode, show_stacktrace ? cle.ToString() : cle.Message);
            }

            catch (Exception) {
                throw;
            }

            finally {
                if (engine != null)
                {
                    engine.UnregisterAllLoggers();
                    result = result && engine.BuildSuccess;
                }

                Environment.Exit(result ? 0 : 1);
            }
        }
コード例 #3
0
        public void Execute()
        {
            bool result          = false;
            bool show_stacktrace = false;

            try {
                parameters.ParseArguments(args);
                show_stacktrace = (parameters.LoggerVerbosity == LoggerVerbosity.Detailed ||
                                   parameters.LoggerVerbosity == LoggerVerbosity.Diagnostic);

                if (!parameters.NoLogo)
                {
                    ErrorUtilities.ShowVersion(false);
                }

                project_collection = new ProjectCollection();
                if (!String.IsNullOrEmpty(parameters.ToolsVersion))
                {
                    if (project_collection.GetToolset(parameters.ToolsVersion) == null)
                    {
                        ErrorUtilities.ReportError(0, new InvalidToolsetDefinitionException("Toolset " + parameters.ToolsVersion + " was not found").Message);
                    }

                    project_collection.DefaultToolsVersion = parameters.ToolsVersion;
                }

                foreach (var p in parameters.Properties)
                {
                    project_collection.GlobalProperties.Add(p.Key, p.Value);
                }

                if (!parameters.NoConsoleLogger)
                {
                    printer = new ConsoleReportPrinter();
                    ConsoleLogger cl = new ConsoleLogger(parameters.LoggerVerbosity,
                                                         printer.Print, printer.SetForeground, printer.ResetColor);

                    cl.Parameters = parameters.ConsoleLoggerParameters;
                    cl.Verbosity  = parameters.LoggerVerbosity;
                    project_collection.RegisterLogger(cl);
                }

                if (parameters.FileLoggerParameters != null)
                {
                    for (int i = 0; i < parameters.FileLoggerParameters.Length; i++)
                    {
                        string fl_params = parameters.FileLoggerParameters [i];
                        if (fl_params == null)
                        {
                            continue;
                        }

                        var fl = new FileLogger();
                        if (fl_params.Length == 0 && i > 0)
                        {
                            fl.Parameters = String.Format("LogFile=msbuild{0}.log", i);
                        }
                        else
                        {
                            fl.Parameters = fl_params;
                        }
                        project_collection.RegisterLogger(fl);
                    }
                }

                foreach (LoggerInfo li in parameters.Loggers)
                {
                    Assembly assembly;
                    if (li.InfoType == LoadInfoType.AssemblyFilename)
                    {
                        assembly = Assembly.LoadFrom(li.Filename);
                    }
                    else
                    {
                        assembly = Assembly.Load(li.AssemblyName);
                    }
                    ILogger logger = (ILogger)Activator.CreateInstance(assembly.GetType(li.ClassName));
                    logger.Parameters = li.Parameters;
                    project_collection.RegisterLogger(logger);
                }

                string projectFile = parameters.ProjectFile;
                if (!File.Exists(projectFile))
                {
                    ErrorUtilities.ReportError(0, String.Format("Project file '{0}' not found.", projectFile));
                    return;
                }

                XmlReaderSettings settings = new XmlReaderSettings();
                if (parameters.Validate)
                {
                    settings.ValidationType = ValidationType.Schema;
                    if (parameters.ValidationSchema == null)
                    {
                        using (var xsdxml = XmlReader.Create(defaultSchema))
                            settings.Schemas.Add(XmlSchema.Read(xsdxml, null));
                    }
                    else
                    {
                        using (var xsdxml = XmlReader.Create(parameters.ValidationSchema))
                            settings.Schemas.Add(XmlSchema.Read(xsdxml, null));
                    }
                }

                var projectInstances = new List <ProjectInstance> ();
                if (string.Equals(Path.GetExtension(projectFile), ".sln", StringComparison.OrdinalIgnoreCase))
                {
                    var parser = new SolutionParser();
                    var root   = ProjectRootElement.Create(project_collection);
                    root.FullPath = projectFile;
                    parser.ParseSolution(projectFile, project_collection, root, LogWarning);
                    projectInstances.Add(new Project(root, parameters.Properties, parameters.ToolsVersion, project_collection).CreateProjectInstance());
                }
                else
                {
                    project          = ProjectRootElement.Create(XmlReader.Create(projectFile, settings), project_collection);
                    project.FullPath = projectFile;
                    var pi = new ProjectInstance(project, parameters.Properties, parameters.ToolsVersion, project_collection);
                    projectInstances.Add(pi);
                }
                foreach (var projectInstance in projectInstances)
                {
                    var targets = parameters.Targets.Length > 0 ? parameters.Targets : projectInstance.DefaultTargets.ToArray();
                    result = projectInstance.Build(targets, parameters.Loggers.Count > 0 ? parameters.Loggers : project_collection.Loggers);
                    if (!result)
                    {
                        break;
                    }
                }
            }

            catch (InvalidProjectFileException ipfe) {
                ErrorUtilities.ReportError(0, show_stacktrace ? ipfe.ToString() : ipfe.Message);
            }

            catch (InternalLoggerException ile) {
                ErrorUtilities.ReportError(0, show_stacktrace ? ile.ToString() : ile.Message);
            }

            catch (CommandLineException cle) {
                ErrorUtilities.ReportError(cle.ErrorCode, show_stacktrace ? cle.ToString() : cle.Message);
            }
            finally {
                //if (project_collection != null)
                //	project_collection.UnregisterAllLoggers ();

                Environment.Exit(result ? 0 : 1);
            }
        }
コード例 #4
0
ファイル: Main.cs プロジェクト: nobled/mono
		public void Execute ()
		{
			bool result = false;
			bool show_stacktrace = false;
			
			try {
				parameters.ParseArguments (args);
				show_stacktrace = (parameters.LoggerVerbosity == LoggerVerbosity.Detailed ||
					parameters.LoggerVerbosity == LoggerVerbosity.Diagnostic);
				
				if (!parameters.NoLogo)
					ErrorUtilities.ShowVersion (false);
				
				engine  = Engine.GlobalEngine;
				if (!String.IsNullOrEmpty (parameters.ToolsVersion)) {
					if (engine.Toolsets [parameters.ToolsVersion] == null)
						ErrorUtilities.ReportError (0, new UnknownToolsVersionException (parameters.ToolsVersion).Message);

					engine.DefaultToolsVersion = parameters.ToolsVersion;
				}
				
				engine.GlobalProperties = this.parameters.Properties;
				
				if (!parameters.NoConsoleLogger) {
					printer = new ConsoleReportPrinter ();
					ConsoleLogger cl = new ConsoleLogger (parameters.LoggerVerbosity,
							printer.Print, printer.SetForeground, printer.ResetColor);

					cl.Parameters = parameters.ConsoleLoggerParameters;
					cl.Verbosity = parameters.LoggerVerbosity; 
					engine.RegisterLogger (cl);
				}

				if (parameters.FileLoggerParameters != null) {
					for (int i = 0; i < parameters.FileLoggerParameters.Length; i ++) {
						string fl_params = parameters.FileLoggerParameters [i];
						if (fl_params == null)
							continue;

						var fl = new FileLogger ();
						if (fl_params.Length == 0 && i > 0)
							fl.Parameters = String.Format ("LogFile=msbuild{0}.log", i);
						else
							fl.Parameters = fl_params;
						engine.RegisterLogger (fl);
					}
				}
				
				foreach (LoggerInfo li in parameters.Loggers) {
					Assembly assembly;
					if (li.InfoType == LoadInfoType.AssemblyFilename)
						assembly = Assembly.LoadFrom (li.Filename);
					else
						assembly = Assembly.Load (li.AssemblyName);
					ILogger logger = (ILogger)Activator.CreateInstance (assembly.GetType (li.ClassName));
					logger.Parameters = li.Parameters;
					engine.RegisterLogger (logger); 
				}
				
				project = engine.CreateNewProject ();
				
				if (parameters.Validate) {
					if (parameters.ValidationSchema == null)
						project.SchemaFile = defaultSchema;
					else
						project.SchemaFile = parameters.ValidationSchema;
				}

				string projectFile = parameters.ProjectFile;
				if (!File.Exists (projectFile)) {
					ErrorUtilities.ReportError (0, String.Format ("Project file '{0}' not found.", projectFile));
					return;
				}

				result = engine.BuildProjectFile (projectFile, parameters.Targets, null, null, BuildSettings.None, parameters.ToolsVersion);
			}
			
			catch (InvalidProjectFileException ipfe) {
				ErrorUtilities.ReportError (0, show_stacktrace ? ipfe.ToString () : ipfe.Message);
			}

			catch (InternalLoggerException ile) {
				ErrorUtilities.ReportError (0, show_stacktrace ? ile.ToString () : ile.Message);
			}

			catch (CommandLineException cle) {
				ErrorUtilities.ReportError(cle.ErrorCode, show_stacktrace ? cle.ToString() : cle.Message);
			}
			finally {
				if (engine != null)
					engine.UnregisterAllLoggers ();

				Environment.Exit (result ? 0 : 1);
			}

		}
コード例 #5
0
ファイル: Main.cs プロジェクト: Profit0004/mono
		public void Execute ()
		{
			bool result = false;
			bool show_stacktrace = false;
			
			try {
				parameters.ParseArguments (args);
				show_stacktrace = (parameters.LoggerVerbosity == LoggerVerbosity.Detailed ||
					parameters.LoggerVerbosity == LoggerVerbosity.Diagnostic);
				
				if (!parameters.NoLogo)
					ErrorUtilities.ShowVersion (false);
				
				project_collection  = new ProjectCollection ();
				if (!String.IsNullOrEmpty (parameters.ToolsVersion)) {
					if (project_collection.GetToolset (parameters.ToolsVersion) == null)
						ErrorUtilities.ReportError (0, new InvalidToolsetDefinitionException ("Toolset " + parameters.ToolsVersion + " was not found").Message);

					project_collection.DefaultToolsVersion = parameters.ToolsVersion;
				}
				
				foreach (var p in parameters.Properties)
					project_collection.GlobalProperties.Add (p.Key, p.Value);
				
				if (!parameters.NoConsoleLogger) {
					printer = new ConsoleReportPrinter ();
					ConsoleLogger cl = new ConsoleLogger (parameters.LoggerVerbosity,
							printer.Print, printer.SetForeground, printer.ResetColor);

					cl.Parameters = parameters.ConsoleLoggerParameters;
					cl.Verbosity = parameters.LoggerVerbosity; 
					project_collection.RegisterLogger (cl);
				}

				if (parameters.FileLoggerParameters != null) {
					for (int i = 0; i < parameters.FileLoggerParameters.Length; i ++) {
						string fl_params = parameters.FileLoggerParameters [i];
						if (fl_params == null)
							continue;

						var fl = new FileLogger ();
						if (fl_params.Length == 0 && i > 0)
							fl.Parameters = String.Format ("LogFile=msbuild{0}.log", i);
						else
							fl.Parameters = fl_params;
						project_collection.RegisterLogger (fl);
					}
				}
				
				foreach (LoggerInfo li in parameters.Loggers) {
					Assembly assembly;
					if (li.InfoType == LoadInfoType.AssemblyFilename)
						assembly = Assembly.LoadFrom (li.Filename);
					else
						assembly = Assembly.Load (li.AssemblyName);
					ILogger logger = (ILogger)Activator.CreateInstance (assembly.GetType (li.ClassName));
					logger.Parameters = li.Parameters;
					project_collection.RegisterLogger (logger); 
				}
				
				string projectFile = parameters.ProjectFile;
				if (!File.Exists (projectFile)) {
					ErrorUtilities.ReportError (0, String.Format ("Project file '{0}' not found.", projectFile));
					return;
				}

				XmlReaderSettings settings = new XmlReaderSettings ();
				if (parameters.Validate) {
					settings.ValidationType = ValidationType.Schema;
					if (parameters.ValidationSchema == null)
						using (var xsdxml = XmlReader.Create (defaultSchema))
							settings.Schemas.Add (XmlSchema.Read (xsdxml, null));
					else
						using (var xsdxml = XmlReader.Create (parameters.ValidationSchema))
							settings.Schemas.Add (XmlSchema.Read (xsdxml, null));
				}

				var projectInstances = new List<ProjectInstance> ();
				if (string.Equals (Path.GetExtension (projectFile), ".sln", StringComparison.OrdinalIgnoreCase)) {
					var parser = new SolutionParser ();
					var root = ProjectRootElement.Create (project_collection);
					root.FullPath = projectFile;
					parser.ParseSolution (projectFile, project_collection, root, LogWarning);
					projectInstances.Add (new Project (root, parameters.Properties, parameters.ToolsVersion, project_collection).CreateProjectInstance ());
				} else {
					project = ProjectRootElement.Create (XmlReader.Create (projectFile, settings), project_collection);
					project.FullPath = projectFile;
					var pi = new ProjectInstance (project, parameters.Properties, parameters.ToolsVersion, project_collection);
					projectInstances.Add (pi);
				}
				foreach (var projectInstance in projectInstances) {
					var targets = parameters.Targets.Length > 0 ? parameters.Targets : projectInstance.DefaultTargets.ToArray ();
					result = projectInstance.Build (targets, parameters.Loggers.Count > 0 ? parameters.Loggers : project_collection.Loggers);
					if (!result)
						break;
				}
			}
			
			catch (InvalidProjectFileException ipfe) {
				ErrorUtilities.ReportError (0, show_stacktrace ? ipfe.ToString () : ipfe.Message);
			}

			catch (InternalLoggerException ile) {
				ErrorUtilities.ReportError (0, show_stacktrace ? ile.ToString () : ile.Message);
			}

			catch (CommandLineException cle) {
				ErrorUtilities.ReportError(cle.ErrorCode, show_stacktrace ? cle.ToString() : cle.Message);
			}
			finally {
				//if (project_collection != null)
				//	project_collection.UnregisterAllLoggers ();

				Environment.Exit (result ? 0 : 1);
			}
		}
コード例 #6
0
		public void Execute ()
		{
			bool result = false;
			bool show_stacktrace = false;
			
			try {
				parameters.ParseArguments (args);
				show_stacktrace = (parameters.LoggerVerbosity == LoggerVerbosity.Detailed ||
					parameters.LoggerVerbosity == LoggerVerbosity.Diagnostic);
				
				if (parameters.DisplayVersion)
					ErrorUtilities.ShowVersion (false);
				
				engine  = new Engine (binPath);
				
				engine.GlobalProperties = this.parameters.Properties;
				
				if (!parameters.NoConsoleLogger) {
					printer = new ConsoleReportPrinter ();
					ConsoleLogger cl = new ConsoleLogger (parameters.LoggerVerbosity,
							printer.Print, printer.SetForeground, printer.ResetColor);

					cl.Parameters = parameters.ConsoleLoggerParameters;
					cl.Verbosity = parameters.LoggerVerbosity; 
					engine.RegisterLogger (cl);
				}
				
				foreach (LoggerInfo li in parameters.Loggers) {
					Assembly assembly;
					if (li.InfoType == LoadInfoType.AssemblyFilename)
						assembly = Assembly.LoadFrom (li.Filename);
					else
						assembly = Assembly.Load (li.AssemblyName);
					ILogger logger = (ILogger)Activator.CreateInstance (assembly.GetType (li.ClassName));
					logger.Parameters = li.Parameters;
					engine.RegisterLogger (logger); 
				}
				
				project = engine.CreateNewProject ();
				
				if (parameters.Validate) {
					if (parameters.ValidationSchema == null)
						project.SchemaFile = defaultSchema;
					else
						project.SchemaFile = parameters.ValidationSchema;
				}

				string projectFile = parameters.ProjectFile;
				if (!File.Exists (projectFile)) {
					ErrorUtilities.ReportError (0, String.Format ("Project file '{0}' not found.", projectFile));
					return;
				}

				project.Load (projectFile);
				
				string oldCurrentDirectory = Environment.CurrentDirectory;
				string dir = Path.GetDirectoryName (projectFile);
				if (!String.IsNullOrEmpty (dir))
					Directory.SetCurrentDirectory (dir);
				result = engine.BuildProject (project, parameters.Targets, null);
				Directory.SetCurrentDirectory (oldCurrentDirectory);
			}
			
			catch (InvalidProjectFileException ipfe) {
				ErrorUtilities.ReportError (0, show_stacktrace ? ipfe.ToString () : ipfe.Message);
			}

			catch (InternalLoggerException ile) {
				ErrorUtilities.ReportError (0, show_stacktrace ? ile.ToString () : ile.Message);
			}

			catch (CommandLineException cle) {
				ErrorUtilities.ReportError(cle.ErrorCode, show_stacktrace ? cle.ToString() : cle.Message);
			}

			catch (Exception) {
				throw;
			}
			
			finally {
				if (engine != null)
					engine.UnregisterAllLoggers ();

				Environment.Exit (result ? 0 : 1);
			}

		}