Example #1
0
		public MSBuildResult[] RunTarget (string target, ProjectConfigurationInfo[] configurations, ILogWriter logWriter,
			MSBuildVerbosity verbosity)
		{
			MSBuildResult[] result = null;
			BuildEngine.RunSTA (delegate
			{
				try {
					var project = SetupProject (configurations);
					currentLogWriter = logWriter;

					var logger = new LocalLogger (file);
					buildEngine.Engine.UnregisterAllLoggers ();
					buildEngine.Engine.RegisterLogger (logger);
					buildEngine.Engine.RegisterLogger (consoleLogger);

					consoleLogger.Verbosity = GetVerbosity (verbosity);

					// We are using this BuildProject overload and the BuildSettings.None argument as a workaround to
					// an xbuild bug which causes references to not be resolved after the project has been built once.
					buildEngine.Engine.BuildProject (project, new [] { target }, new Hashtable (), BuildSettings.None);
					
					result = logger.BuildResult.ToArray ();
				} catch (InvalidProjectFileException ex) {
					var r = new MSBuildResult (
						file, false, ex.ErrorSubcategory, ex.ErrorCode, ex.ProjectFile,
						ex.LineNumber, ex.ColumnNumber, ex.EndLineNumber, ex.EndColumnNumber,
						ex.BaseMessage, ex.HelpKeyword);
					logWriter.WriteLine (r.ToString ());
					result = new [] { r };
				} finally {
					currentLogWriter = null;
				}
			});
			return result;
		}
Example #2
0
        public MSBuildResult[] RunTarget(string target, ProjectConfigurationInfo[] configurations, ILogWriter logWriter,
                                         MSBuildVerbosity verbosity)
        {
            MSBuildResult[] result = null;
            BuildEngine.RunSTA(delegate
            {
                try {
                    var project      = SetupProject(configurations);
                    currentLogWriter = logWriter;

                    LocalLogger logger = new LocalLogger(Path.GetDirectoryName(file));
                    engine.UnregisterAllLoggers();
                    engine.RegisterLogger(logger);
                    engine.RegisterLogger(consoleLogger);

                    consoleLogger.Verbosity = GetVerbosity(verbosity);

                    project.Build(target);

                    result = logger.BuildResult.ToArray();
                    //		} catch (InvalidProjectFileException ex) {
                    //			result = new MSBuildResult[] { new MSBuildResult (false, ex.ProjectFile ?? file, ex.LineNumber, ex.ColumnNumber, ex.ErrorCode, ex.Message) };
                } finally {
                    currentLogWriter = null;
                }
            });
            return(result);
        }
		public MSBuildResult[] RunTarget (string target, ProjectConfigurationInfo[] configurations, ILogWriter logWriter,
			MSBuildVerbosity verbosity)
		{
			MSBuildResult[] result = null;
			BuildEngine.RunSTA (delegate
			{
				try {
					var project = SetupProject (configurations);
					currentLogWriter = logWriter;

					LocalLogger logger = new LocalLogger (Path.GetDirectoryName (file));
					engine.UnregisterAllLoggers ();
					engine.RegisterLogger (logger);
					engine.RegisterLogger (consoleLogger);

					consoleLogger.Verbosity = GetVerbosity (verbosity);
					
					project.Build (target);
					
					result = logger.BuildResult.ToArray ();
		//		} catch (InvalidProjectFileException ex) {
		//			result = new MSBuildResult[] { new MSBuildResult (false, ex.ProjectFile ?? file, ex.LineNumber, ex.ColumnNumber, ex.ErrorCode, ex.Message) };
				} finally {
					currentLogWriter = null;
				}
			});
			return result;
		}
Example #4
0
        public MSBuildResult[] RunTarget(string target, ProjectConfigurationInfo[] configurations, ILogWriter logWriter,
                                         MSBuildVerbosity verbosity)
        {
            MSBuildResult[] result = null;
            BuildEngine.RunSTA(delegate
            {
                try {
                    var project      = SetupProject(configurations);
                    currentLogWriter = logWriter;

                    LocalLogger logger = new LocalLogger(Path.GetDirectoryName(file));
                    engine.UnregisterAllLoggers();
                    engine.RegisterLogger(logger);
                    engine.RegisterLogger(consoleLogger);

                    consoleLogger.Verbosity = GetVerbosity(verbosity);

                    // We are using this BuildProject overload and the BuildSettings.None argument as a workaround to
                    // an xbuild bug which causes references to not be resolved after the project has been built once.
                    engine.BuildProject(project, new string[] { target }, new Hashtable(), BuildSettings.None);

                    result = logger.BuildResult.ToArray();
                } catch (InvalidProjectFileException ex) {
                    result = new MSBuildResult[] { new MSBuildResult(false, ex.ProjectFile ?? file, ex.LineNumber, ex.ColumnNumber, ex.ErrorCode, ex.Message) };
                } finally {
                    currentLogWriter = null;
                }
            });
            return(result);
        }
        public MSBuildResult[] RunTarget(string target, ProjectConfigurationInfo[] configurations, ILogWriter logWriter,
                                         MSBuildVerbosity verbosity)
        {
            MSBuildResult[] result = null;
            BuildEngine.RunSTA(delegate
            {
                try {
                    var project      = SetupProject(configurations);
                    currentLogWriter = logWriter;

                    var logger = new LocalLogger(file);
                    engine.UnregisterAllLoggers();
                    engine.RegisterLogger(logger);
                    engine.RegisterLogger(consoleLogger);

                    consoleLogger.Verbosity = GetVerbosity(verbosity);

                    project.Build(target);

                    result = logger.BuildResult.ToArray();
                } catch (Microsoft.Build.Exceptions.InvalidProjectFileException ex) {
                    var r = new MSBuildResult(
                        file, false, ex.ErrorSubcategory, ex.ErrorCode, ex.ProjectFile,
                        ex.LineNumber, ex.ColumnNumber, ex.EndLineNumber, ex.EndColumnNumber,
                        ex.BaseMessage, ex.HelpKeyword);
                    logWriter.WriteLine(r.ToString());
                    result = new [] { r };
                } finally {
                    currentLogWriter = null;
                }
            });
            return(result);
        }
Example #6
0
        public MSBuildResult[] RunTarget(string target, string configuration, string platform, ILogWriter logWriter)
        {
            try {
                SetupEngine(configuration, platform);

                LocalLogger logger = new LocalLogger(Path.GetDirectoryName(file));
                engine.RegisterLogger(logger);

                ConsoleLogger consoleLogger = new ConsoleLogger(LoggerVerbosity.Normal, logWriter.WriteLine, null, null);
                engine.RegisterLogger(consoleLogger);

                project.Build(target);
                return(logger.BuildResult.ToArray());
            } finally {
                engine.UnregisterAllLoggers();
            }
        }
		public MSBuildResult[] RunTarget (string target, string configuration, string platform, ILogWriter logWriter)
		{
			try {
				SetupEngine (configuration, platform);
				
				LocalLogger logger = new LocalLogger (Path.GetDirectoryName (file));
				engine.RegisterLogger (logger);
				
				ConsoleLogger consoleLogger = new ConsoleLogger (LoggerVerbosity.Normal, logWriter.WriteLine, null, null);
				engine.RegisterLogger (consoleLogger);
				
				project.Build (target);
				return logger.BuildResult.ToArray ();
				
			} finally {
				engine.UnregisterAllLoggers ();
			}
		}
Example #8
0
		public MSBuildResult[] RunTarget (string target, string configuration, string platform, ILogWriter logWriter,
			MSBuildVerbosity verbosity)
		{
			try {
				SetupEngine (configuration, platform);
				currentLogWriter = logWriter;
				
				LocalLogger logger = new LocalLogger (Path.GetDirectoryName (file));
				engine.RegisterLogger (logger);
				
				consoleLogger.Verbosity = GetVerbosity (verbosity);
				project.Build (target);
				return logger.BuildResult.ToArray ();
				
			} finally {
				currentLogWriter = null;
			}
		}
Example #9
0
        public MSBuildResult Run(
            ProjectConfigurationInfo[] configurations, ILogWriter logWriter, MSBuildVerbosity verbosity,
            string[] runTargets, string[] evaluateItems, string[] evaluateProperties)
        {
            if (runTargets == null || runTargets.Length == 0)
            {
                throw new ArgumentException("runTargets is empty");
            }

            MSBuildResult result = null;

            BuildEngine.RunSTA(delegate {
                try {
                    var project      = SetupProject(configurations);
                    currentLogWriter = logWriter;

                    ILogger[] loggers;
                    var logger = new LocalLogger(file);
                    if (logWriter != null)
                    {
                        consoleLogger.Verbosity = GetVerbosity(verbosity);
                        loggers = new ILogger[] { logger, consoleLogger };
                    }
                    else
                    {
                        loggers = new ILogger[] { logger };
                    }

                    //building the project will create items and alter properties, so we use a new instance
                    var pi = project.CreateProjectInstance();

                    pi.Build(runTargets, loggers);

                    result = new MSBuildResult(logger.BuildResult.ToArray());

                    if (evaluateProperties != null)
                    {
                        foreach (var name in evaluateProperties)
                        {
                            var prop = pi.GetProperty(name);
                            result.Properties [name] = prop != null? prop.EvaluatedValue : null;
                        }
                    }

                    if (evaluateItems != null)
                    {
                        foreach (var name in evaluateItems)
                        {
                            var grp  = pi.GetItems(name);
                            var list = new List <MSBuildEvaluatedItem> ();
                            foreach (var item in grp)
                            {
                                var evItem = new MSBuildEvaluatedItem(name, UnescapeString(item.EvaluatedInclude));
                                foreach (var m in item.Metadata)
                                {
                                    evItem.Metadata [m.Name] = UnescapeString(m.EvaluatedValue);
                                }
                                list.Add(evItem);
                            }
                            result.Items[name] = list;
                        }
                    }
                } catch (Microsoft.Build.Exceptions.InvalidProjectFileException ex) {
                    var r = new MSBuildTargetResult(
                        file, false, ex.ErrorSubcategory, ex.ErrorCode, ex.ProjectFile,
                        ex.LineNumber, ex.ColumnNumber, ex.EndLineNumber, ex.EndColumnNumber,
                        ex.BaseMessage, ex.HelpKeyword);
                    logWriter.WriteLine(r.ToString());
                    result = new MSBuildResult(new [] { r });
                } finally {
                    currentLogWriter = null;
                }
            });
            return(result);
        }
Example #10
0
		public MSBuildResult Run (
			ProjectConfigurationInfo[] configurations, ILogWriter logWriter, MSBuildVerbosity verbosity,
			string[] runTargets, string[] evaluateItems, string[] evaluateProperties, Dictionary<string,string> globalProperties)
		{
			MSBuildResult result = null;
			BuildEngine.RunSTA (delegate {
				try {
					var project = SetupProject (configurations);
					currentLogWriter = logWriter;

					buildEngine.Engine.UnregisterAllLoggers ();

					var logger = new LocalLogger (file);
					buildEngine.Engine.RegisterLogger (logger);
					if (logWriter != null) {
						buildEngine.Engine.RegisterLogger (consoleLogger);
						consoleLogger.Verbosity = GetVerbosity (verbosity);
					}

					if (runTargets != null && runTargets.Length > 0) {
						if (globalProperties != null) {
							foreach (var p in globalProperties)
								project.GlobalProperties.SetProperty (p.Key, p.Value);
						}
						// We are using this BuildProject overload and the BuildSettings.None argument as a workaround to
						// an xbuild bug which causes references to not be resolved after the project has been built once.
						buildEngine.Engine.BuildProject (project, runTargets, new Hashtable (), BuildSettings.None);

						if (globalProperties != null) {
							foreach (var p in globalProperties.Keys) {
								project.GlobalProperties.RemoveProperty (p);
								buildEngine.Engine.GlobalProperties.RemoveProperty (p);
							}
						}
					}

					result = new MSBuildResult (logger.BuildResult.ToArray ());

					if (evaluateProperties != null) {
						foreach (var name in evaluateProperties)
							result.Properties [name] = project.GetEvaluatedProperty (name);
					}

					if (evaluateItems != null) {
						foreach (var name in evaluateItems) {
							BuildItemGroup grp = project.GetEvaluatedItemsByName (name);
							var list = new List<MSBuildEvaluatedItem> ();
							foreach (BuildItem item in grp) {
								var evItem = new MSBuildEvaluatedItem (name, UnescapeString (item.FinalItemSpec));
								foreach (DictionaryEntry de in (IDictionary) evaluatedMetadataField.GetValue (item)) {
									evItem.Metadata [(string)de.Key] = UnescapeString ((string)de.Value);
								}
								list.Add (evItem);
							}
							result.Items[name] = list;
						}
					}
				} catch (InvalidProjectFileException ex) {
					var r = new MSBuildTargetResult (
						file, false, ex.ErrorSubcategory, ex.ErrorCode, ex.ProjectFile,
						ex.LineNumber, ex.ColumnNumber, ex.EndLineNumber, ex.EndColumnNumber,
						ex.BaseMessage, ex.HelpKeyword);
					if (logWriter != null)
						logWriter.WriteLine (r.ToString ());
					result = new MSBuildResult (new [] { r });
				} finally {
					currentLogWriter = null;
				}
			});
			return result;
		}
Example #11
0
        public MSBuildResult Run(
            ProjectConfigurationInfo[] configurations, ILogWriter logWriter, MSBuildVerbosity verbosity,
            string[] runTargets, string[] evaluateItems, string[] evaluateProperties)
        {
            MSBuildResult result = null;

            BuildEngine.RunSTA(delegate {
                try {
                    var project      = SetupProject(configurations);
                    currentLogWriter = logWriter;

                    buildEngine.Engine.UnregisterAllLoggers();

                    var logger = new LocalLogger(file);
                    buildEngine.Engine.RegisterLogger(logger);
                    if (logWriter != null)
                    {
                        buildEngine.Engine.RegisterLogger(consoleLogger);
                        consoleLogger.Verbosity = GetVerbosity(verbosity);
                    }

                    if (runTargets != null && runTargets.Length > 0)
                    {
                        // We are using this BuildProject overload and the BuildSettings.None argument as a workaround to
                        // an xbuild bug which causes references to not be resolved after the project has been built once.
                        buildEngine.Engine.BuildProject(project, runTargets, new Hashtable(), BuildSettings.None);
                    }

                    result = new MSBuildResult(logger.BuildResult.ToArray());

                    if (evaluateProperties != null)
                    {
                        foreach (var name in evaluateProperties)
                        {
                            result.Properties [name] = project.GetEvaluatedProperty(name);
                        }
                    }

                    if (evaluateItems != null)
                    {
                        foreach (var name in evaluateItems)
                        {
                            BuildItemGroup grp = project.GetEvaluatedItemsByName(name);
                            var list           = new List <MSBuildEvaluatedItem> ();
                            foreach (BuildItem item in grp)
                            {
                                var evItem = new MSBuildEvaluatedItem(name, UnescapeString(item.FinalItemSpec));
                                foreach (DictionaryEntry de in (IDictionary)evaluatedMetadataField.GetValue(item))
                                {
                                    evItem.Metadata [(string)de.Key] = UnescapeString((string)de.Value);
                                }
                                list.Add(evItem);
                            }
                            result.Items[name] = list;
                        }
                    }
                } catch (InvalidProjectFileException ex) {
                    var r = new MSBuildTargetResult(
                        file, false, ex.ErrorSubcategory, ex.ErrorCode, ex.ProjectFile,
                        ex.LineNumber, ex.ColumnNumber, ex.EndLineNumber, ex.EndColumnNumber,
                        ex.BaseMessage, ex.HelpKeyword);
                    logWriter.WriteLine(r.ToString());
                    result = new MSBuildResult(new [] { r });
                } finally {
                    currentLogWriter = null;
                }
            });
            return(result);
        }
Example #12
0
		public MSBuildResult[] RunTarget (string target, string configuration, string platform, ILogWriter logWriter,
			MSBuildVerbosity verbosity)
		{
			MSBuildResult[] result = null;
			RunSTA (delegate
			{
				try {
					SetupProject (configuration, platform);
					currentLogWriter = logWriter;

					LocalLogger logger = new LocalLogger (Path.GetDirectoryName (file));
					engine.RegisterLogger (logger);

					consoleLogger.Verbosity = GetVerbosity (verbosity);
					
					// We are using this BuildProject overload and the BuildSettings.None argument as a workaround to
					// an xbuild bug which causes references to not be resolved after the project has been built once.
					engine.BuildProject (project, new string[] { target }, new Hashtable (), BuildSettings.None);
					
					result = logger.BuildResult.ToArray ();
				} catch (InvalidProjectFileException ex) {
					result = new MSBuildResult[] { new MSBuildResult (false, ex.ProjectFile ?? file, ex.LineNumber, ex.ColumnNumber, ex.ErrorCode, ex.Message) };
				} finally {
					currentLogWriter = null;
				}
			});
			return result;
		}
		public MSBuildResult Run (
			ProjectConfigurationInfo[] configurations, ILogWriter logWriter, MSBuildVerbosity verbosity,
			string[] runTargets, string[] evaluateItems, string[] evaluateProperties, Dictionary<string,string> globalProperties)
		{
			if (runTargets == null || runTargets.Length == 0)
				throw new ArgumentException ("runTargets is empty");

			MSBuildResult result = null;
			BuildEngine.RunSTA (delegate {
				try {
					var project = SetupProject (configurations);
					currentLogWriter = logWriter;

					ILogger[] loggers;
					var logger = new LocalLogger (file);
					if (logWriter != null) {
						var consoleLogger = new ConsoleLogger (GetVerbosity (verbosity), LogWriteLine, null, null);
						loggers = new ILogger[] { logger, consoleLogger };
					} else {
						loggers = new ILogger[] { logger };
					}

					//building the project will create items and alter properties, so we use a new instance
					var pi = project.CreateProjectInstance ();

					if (globalProperties != null)
						foreach (var p in globalProperties)
							pi.SetProperty (p.Key, p.Value);

					pi.Build (runTargets, loggers);

					result = new MSBuildResult (logger.BuildResult.ToArray ());

					if (evaluateProperties != null) {
						foreach (var name in evaluateProperties) {
							var prop = pi.GetProperty (name);
							result.Properties [name] = prop != null? prop.EvaluatedValue : null;
						}
					}

					if (evaluateItems != null) {
						foreach (var name in evaluateItems) {
							var grp = pi.GetItems (name);
							var list = new List<MSBuildEvaluatedItem> ();
							foreach (var item in grp) {
								var evItem = new MSBuildEvaluatedItem (name, UnescapeString (item.EvaluatedInclude));
								foreach (var m in item.Metadata) {
									evItem.Metadata [m.Name] = UnescapeString (m.EvaluatedValue);
								}
								list.Add (evItem);
							}
							result.Items[name] = list;
						}
					}
				} catch (Microsoft.Build.Exceptions.InvalidProjectFileException ex) {
					var r = new MSBuildTargetResult (
						file, false, ex.ErrorSubcategory, ex.ErrorCode, ex.ProjectFile,
						ex.LineNumber, ex.ColumnNumber, ex.EndLineNumber, ex.EndColumnNumber,
						ex.BaseMessage, ex.HelpKeyword);
					if (logWriter != null)
						logWriter.WriteLine (r.ToString ());
					result = new MSBuildResult (new [] { r });
				} finally {
					currentLogWriter = null;
				}
			});
			return result;
		}
Example #14
0
		public MSBuildResult[] RunTarget (string target, ProjectConfigurationInfo[] configurations, ILogWriter logWriter,
			MSBuildVerbosity verbosity)
		{
			MSBuildResult[] result = null;
			BuildEngine.RunSTA (delegate
			{
				try {
					var project = SetupProject (configurations);
					currentLogWriter = logWriter;

					var logger = new LocalLogger (file);
					engine.UnregisterAllLoggers ();
					engine.RegisterLogger (logger);
					engine.RegisterLogger (consoleLogger);

					consoleLogger.Verbosity = GetVerbosity (verbosity);
					
					project.Build (target);
					
					result = logger.BuildResult.ToArray ();
				} catch (Microsoft.Build.Exceptions.InvalidProjectFileException ex) {
						var r = new MSBuildResult (
							file, false, ex.ErrorSubcategory, ex.ErrorCode, ex.ProjectFile,
							ex.LineNumber, ex.ColumnNumber, ex.EndLineNumber, ex.EndColumnNumber,
							ex.BaseMessage, ex.HelpKeyword);
						logWriter.WriteLine (r.ToString ());
						result = new [] { r };
				} finally {
					currentLogWriter = null;
				}
			});
			return result;
		}