/SolutionFramework/VisualStudioProvider/MSBuild/Build/CommandLine/MSBuildApp.cs
C# | 1683 lines | 1662 code | 21 blank | 0 comment | 130 complexity | 6f20dca73f1c5ceb3e7db1cb93c087dc MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0
Large files files are truncated, but you can click here to view the full file
- namespace Microsoft.Build.CommandLine
- {
- using Microsoft.Build.BuildEngine;
- using Microsoft.Build.Evaluation;
- using Microsoft.Build.Exceptions;
- using Microsoft.Build.Execution;
- using Microsoft.Build.Framework;
- using Microsoft.Build.Logging;
- using Microsoft.Build.Shared;
- using Microsoft.Internal.Performance;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Diagnostics;
- using System.Globalization;
- using System.IO;
- using System.Reflection;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
- using System.Security;
- using System.Text;
- using System.Threading;
-
- public static class MSBuildApp
- {
- private static BuildSubmission activeBuild;
- private const string autoResponseFileName = "MSBuild.rsp";
- private static ManualResetEvent buildComplete = new ManualResetEvent(false);
- private static object buildLock = new object();
- private static ManualResetEvent cancelComplete = new ManualResetEvent(true);
- private static readonly string exePath;
- private static ArrayList includedResponseFiles;
- private static bool initialized;
- private const string msbuildLogFileName = "msbuild.log";
- private static readonly char[] propertyValueSeparator = new char[] { '=' };
- private static int receivedCancel;
- internal static bool usingSwitchesFromAutoResponseFile = false;
- private static readonly char[] wildcards = new char[] { '*', '?' };
-
- static MSBuildApp()
- {
- try
- {
- exePath = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath);
- initialized = true;
- }
- catch (TypeInitializationException exception)
- {
- if ((exception.InnerException == null) || (exception.InnerException.GetType() != typeof(ConfigurationErrorsException)))
- {
- throw;
- }
- HandleConfigurationException(exception);
- }
- catch (ConfigurationException exception2)
- {
- HandleConfigurationException(exception2);
- }
- }
-
- internal static string AggregateParameters(string anyPrefixingParameter, string[] parametersToAggregate)
- {
- for (int i = 0; i < parametersToAggregate.Length; i++)
- {
- parametersToAggregate[i] = parametersToAggregate[i].Trim(new char[] { ';' });
- }
- string str = anyPrefixingParameter ?? string.Empty;
- return (str + string.Join(";", parametersToAggregate));
- }
-
- internal static bool BuildProject(string projectFile, string[] targets, string toolsVersion, Dictionary<string, string> globalProperties, ILogger[] loggers, LoggerVerbosity verbosity, DistributedLoggerRecord[] distributedLoggerRecords, bool needToValidateProject, string schemaFile, int cpuCount, bool enableNodeReuse, TextWriter preprocessWriter, bool debugger, bool detailedSummary)
- {
- if (string.Equals(Path.GetExtension(projectFile), ".vcproj", StringComparison.OrdinalIgnoreCase) || string.Equals(Path.GetExtension(projectFile), ".dsp", StringComparison.OrdinalIgnoreCase))
- {
- InitializationException.Throw(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("ProjectUpgradeNeededToVcxProj", new object[] { projectFile }), null);
- }
- bool flag = false;
- ProjectCollection projectCollection = null;
- bool onlyLogCriticalEvents = false;
- try
- {
- List<ForwardingLoggerRecord> list = new List<ForwardingLoggerRecord>();
- foreach (DistributedLoggerRecord record in distributedLoggerRecords)
- {
- list.Add(new ForwardingLoggerRecord(record.CentralLogger, record.ForwardingLoggerDescription));
- }
- if ((((loggers.Length == 1) && (verbosity == LoggerVerbosity.Quiet)) && ((loggers[0].Parameters.IndexOf("ENABLEMPLOGGING", StringComparison.OrdinalIgnoreCase) != -1) && (loggers[0].Parameters.IndexOf("DISABLEMPLOGGING", StringComparison.OrdinalIgnoreCase) == -1))) && ((loggers[0].Parameters.IndexOf("V=", StringComparison.OrdinalIgnoreCase) == -1) && (loggers[0].Parameters.IndexOf("VERBOSITY=", StringComparison.OrdinalIgnoreCase) == -1)))
- {
- Type type = loggers[0].GetType();
- Type type2 = typeof(Microsoft.Build.Logging.ConsoleLogger);
- if (type == type2)
- {
- onlyLogCriticalEvents = true;
- }
- }
- projectCollection = new ProjectCollection(globalProperties, loggers, null, Microsoft.Build.Evaluation.ToolsetDefinitionLocations.Registry | Microsoft.Build.Evaluation.ToolsetDefinitionLocations.ConfigurationFile, cpuCount, onlyLogCriticalEvents);
- if (debugger)
- {
- Environment.SetEnvironmentVariable("MSBUILDDEBUGGING", "1");
- }
- if ((toolsVersion != null) && !projectCollection.ContainsToolset(toolsVersion))
- {
- ThrowInvalidToolsVersionInitializationException(projectCollection.Toolsets, toolsVersion);
- }
- if (needToValidateProject && !Microsoft.Build.Shared.FileUtilities.IsSolutionFilename(projectFile))
- {
- Microsoft.Build.Evaluation.Project project = projectCollection.LoadProject(projectFile, globalProperties, toolsVersion);
- Microsoft.Build.Evaluation.Toolset toolset = projectCollection.GetToolset((toolsVersion == null) ? project.ToolsVersion : toolsVersion);
- if (toolset == null)
- {
- ThrowInvalidToolsVersionInitializationException(projectCollection.Toolsets, project.ToolsVersion);
- }
- Microsoft.Build.CommandLine.ProjectSchemaValidationHandler.VerifyProjectSchema(projectFile, schemaFile, toolset.ToolsPath);
- projectCollection.UnloadProject(project);
- }
- if ((preprocessWriter != null) && !Microsoft.Build.Shared.FileUtilities.IsSolutionFilename(projectFile))
- {
- Microsoft.Build.Evaluation.Project project2 = projectCollection.LoadProject(projectFile, globalProperties, toolsVersion);
- project2.SaveLogicalProject(preprocessWriter);
- projectCollection.UnloadProject(project2);
- return flag;
- }
- BuildRequestData requestData = new BuildRequestData(projectFile, globalProperties, toolsVersion, targets, null);
- BuildParameters parameters = new BuildParameters(projectCollection);
- if (!string.Equals(Environment.GetEnvironmentVariable("MSBUILDLOGASYNC"), "1", StringComparison.Ordinal))
- {
- parameters.UseSynchronousLogging = true;
- }
- parameters.EnableNodeReuse = enableNodeReuse;
- parameters.NodeExeLocation = Assembly.GetExecutingAssembly().Location;
- parameters.MaxNodeCount = cpuCount;
- parameters.Loggers = projectCollection.Loggers;
- parameters.ForwardingLoggers = list;
- parameters.ToolsetDefinitionLocations = Microsoft.Build.Evaluation.ToolsetDefinitionLocations.Registry | Microsoft.Build.Evaluation.ToolsetDefinitionLocations.ConfigurationFile;
- parameters.DetailedSummary = detailedSummary;
- if (!string.IsNullOrEmpty(toolsVersion))
- {
- parameters.DefaultToolsVersion = toolsVersion;
- }
- string environmentVariable = Environment.GetEnvironmentVariable("MSBUILDMEMORYUSELIMIT");
- if (!string.IsNullOrEmpty(environmentVariable))
- {
- parameters.MemoryUseLimit = Convert.ToInt32(environmentVariable, CultureInfo.InvariantCulture);
- if (parameters.MemoryUseLimit < parameters.MaxNodeCount)
- {
- parameters.MemoryUseLimit = parameters.MaxNodeCount;
- }
- }
- BuildManager defaultBuildManager = BuildManager.DefaultBuildManager;
- Microsoft.Build.Execution.BuildResult result = null;
- defaultBuildManager.BeginBuild(parameters);
- Exception exception = null;
- try
- {
- try
- {
- lock (buildLock)
- {
- activeBuild = defaultBuildManager.PendBuildRequest(requestData);
- }
- result = activeBuild.Execute();
- }
- finally
- {
- defaultBuildManager.EndBuild();
- }
- }
- catch (Exception exception2)
- {
- exception = exception2;
- flag = false;
- }
- if ((result != null) && (exception == null))
- {
- flag = result.OverallResult == BuildResultCode.Success;
- exception = result.Exception;
- }
- if (exception != null)
- {
- flag = false;
- if (!(exception.GetType() != typeof(Microsoft.Build.Exceptions.InvalidProjectFileException)))
- {
- return flag;
- }
- if ((exception.GetType() == typeof(LoggerException)) || (exception.GetType() == typeof(Microsoft.Build.Exceptions.InternalLoggerException)))
- {
- throw exception;
- }
- if (!(exception.GetType() == typeof(BuildAbortedException)))
- {
- Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("FatalError"));
- Console.WriteLine(exception.ToString());
- Console.WriteLine();
- throw exception;
- }
- }
- return flag;
- }
- catch (Microsoft.Build.Exceptions.InvalidProjectFileException exception3)
- {
- Microsoft.Build.Shared.ErrorUtilities.VerifyThrow(exception3.HasBeenLogged, "Should have been logged");
- flag = false;
- }
- finally
- {
- Microsoft.Build.Shared.FileUtilities.ClearCacheDirectory();
- if (projectCollection != null)
- {
- projectCollection.Dispose();
- }
- }
- return flag;
- }
-
- [MethodImpl(MethodImplOptions.NoInlining)]
- private static bool BuildProjectWithOldOM(string projectFile, string[] targets, string toolsVersion, BuildPropertyGroup propertyBag, ILogger[] loggers, LoggerVerbosity verbosity, DistributedLoggerRecord[] distributedLoggerRecords, bool needToValidateProject, string schemaFile, int cpuCount)
- {
- string directoryName = Path.GetDirectoryName(Assembly.GetAssembly(typeof(MSBuildApp)).Location);
- string localNodeProviderParameters = "msbuildlocation=" + directoryName + ";nodereuse=false";
- Engine engine = new Engine(propertyBag, Microsoft.Build.BuildEngine.ToolsetDefinitionLocations.Registry | Microsoft.Build.BuildEngine.ToolsetDefinitionLocations.ConfigurationFile, cpuCount, localNodeProviderParameters);
- bool flag = false;
- try
- {
- foreach (ILogger logger in loggers)
- {
- engine.RegisterLogger(logger);
- }
- if ((((loggers.Length == 1) && (verbosity == LoggerVerbosity.Quiet)) && ((loggers[0].Parameters.IndexOf("ENABLEMPLOGGING", StringComparison.OrdinalIgnoreCase) != -1) && (loggers[0].Parameters.IndexOf("DISABLEMPLOGGING", StringComparison.OrdinalIgnoreCase) == -1))) && ((loggers[0].Parameters.IndexOf("V=", StringComparison.OrdinalIgnoreCase) == -1) && (loggers[0].Parameters.IndexOf("VERBOSITY=", StringComparison.OrdinalIgnoreCase) == -1)))
- {
- Type type = loggers[0].GetType();
- Type type2 = typeof(Microsoft.Build.Logging.ConsoleLogger);
- if (type == type2)
- {
- engine.OnlyLogCriticalEvents = true;
- }
- }
- Microsoft.Build.BuildEngine.Project project = null;
- try
- {
- project = new Microsoft.Build.BuildEngine.Project(engine, toolsVersion);
- }
- catch (InvalidOperationException exception)
- {
- InitializationException.Throw("InvalidToolsVersionError", toolsVersion, exception, false);
- }
- project.IsValidated = needToValidateProject;
- project.SchemaFile = schemaFile;
- project.Load(projectFile);
- flag = engine.BuildProject(project, targets);
- }
- catch (Microsoft.Build.Exceptions.InvalidProjectFileException)
- {
- }
- finally
- {
- engine.Shutdown();
- }
- return flag;
- }
-
- private static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
- {
- if (e.SpecialKey == ConsoleSpecialKey.ControlBreak)
- {
- e.Cancel = false;
- }
- else
- {
- e.Cancel = true;
- if (Interlocked.CompareExchange(ref receivedCancel, 1, 0) != 1)
- {
- Console.WriteLine(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("AbortingBuild", new object[0]));
- WaitCallback callBack = delegate {
- cancelComplete.Reset();
- if (buildComplete.WaitOne(0, false))
- {
- cancelComplete.Set();
- }
- else
- {
- BuildSubmission activeBuild = null;
- lock (buildLock)
- {
- activeBuild = MSBuildApp.activeBuild;
- }
- if (activeBuild != null)
- {
- BuildManager.DefaultBuildManager.CancelAllSubmissions();
- buildComplete.WaitOne();
- }
- cancelComplete.Set();
- }
- };
- ThreadPool.QueueUserWorkItem(callBack);
- }
- }
- }
-
- private static ILogger CreateAndConfigureLogger(Microsoft.Build.Logging.LoggerDescription loggerDescription, LoggerVerbosity verbosity, string unquotedParameter)
- {
- ILogger logger = null;
- try
- {
- logger = loggerDescription.CreateLogger();
- if (logger == null)
- {
- InitializationException.VerifyThrow(logger != null, "LoggerNotFoundError", unquotedParameter);
- }
- }
- catch (IOException exception)
- {
- InitializationException.Throw("LoggerCreationError", unquotedParameter, exception, false);
- }
- catch (BadImageFormatException exception2)
- {
- InitializationException.Throw("LoggerCreationError", unquotedParameter, exception2, false);
- }
- catch (SecurityException exception3)
- {
- InitializationException.Throw("LoggerCreationError", unquotedParameter, exception3, false);
- }
- catch (ReflectionTypeLoadException exception4)
- {
- InitializationException.Throw("LoggerCreationError", unquotedParameter, exception4, false);
- }
- catch (MemberAccessException exception5)
- {
- InitializationException.Throw("LoggerCreationError", unquotedParameter, exception5, false);
- }
- catch (TargetInvocationException exception6)
- {
- InitializationException.Throw("LoggerFatalError", unquotedParameter, exception6.InnerException, true);
- }
- try
- {
- logger.Verbosity = verbosity;
- if (loggerDescription.LoggerSwitchParameters != null)
- {
- logger.Parameters = loggerDescription.LoggerSwitchParameters;
- }
- }
- catch (LoggerException)
- {
- throw;
- }
- catch (Exception exception7)
- {
- InitializationException.Throw("LoggerFatalError", unquotedParameter, exception7, true);
- }
- return logger;
- }
-
- private static DistributedLoggerRecord CreateForwardingLoggerRecord(ILogger logger, string loggerParameters, LoggerVerbosity defaultVerbosity)
- {
- string str2 = ExtractAnyParameterValue(ExtractAnyLoggerParameter(loggerParameters, new string[] { "verbosity", "v" }));
- LoggerVerbosity verbosity = defaultVerbosity;
- if (!string.IsNullOrEmpty(str2))
- {
- verbosity = ProcessVerbositySwitch(str2);
- }
- Assembly assembly = Assembly.GetAssembly(typeof(ProjectCollection));
- string loggerClassName = "Microsoft.Build.Logging.ConfigurableForwardingLogger";
- string fullName = assembly.GetName().FullName;
- return new DistributedLoggerRecord(logger, new Microsoft.Build.Logging.LoggerDescription(loggerClassName, fullName, null, loggerParameters, verbosity));
- }
-
- private static void DisplayCopyrightMessage()
- {
- Console.WriteLine(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("CopyrightMessage", new object[] { ProjectCollection.Version.ToString(), Environment.Version.ToString() }));
- }
-
- private static void DumpAllInCategory(string currentInstance, PerformanceCounterCategory category, bool initializeOnly)
- {
- if (category.CategoryName.IndexOf("remoting", StringComparison.OrdinalIgnoreCase) == -1)
- {
- System.Diagnostics.PerformanceCounter[] counters;
- try
- {
- counters = category.GetCounters(currentInstance);
- }
- catch (InvalidOperationException)
- {
- return;
- }
- if (!initializeOnly)
- {
- Console.WriteLine("\n{0}{1}{0}", new string('=', 0x29 - (category.CategoryName.Length / 2)), category.CategoryName);
- }
- foreach (System.Diagnostics.PerformanceCounter counter in counters)
- {
- DumpCounter(counter, initializeOnly);
- }
- if (!initializeOnly)
- {
- Console.WriteLine("{0}{0}", new string('=', 0x29));
- }
- }
- }
-
- private static void DumpCounter(System.Diagnostics.PerformanceCounter counter, bool initializeOnly)
- {
- if (counter.CounterName.IndexOf("not displayed", StringComparison.OrdinalIgnoreCase) == -1)
- {
- float num = counter.NextValue();
- if (!initializeOnly)
- {
- string friendlyCounterType = GetFriendlyCounterType(counter.CounterType, counter.CounterName);
- string format = (num < 10f) ? "{0,20:N2}" : "{0,20:N0}";
- string str3 = string.Format(CultureInfo.CurrentCulture, format, new object[] { num });
- Console.WriteLine("||{0,50}|{1}|{2,8}|", counter.CounterName, str3, friendlyCounterType);
- }
- }
- }
-
- private static void DumpCounters(bool initializeOnly)
- {
- Process currentProcess = Process.GetCurrentProcess();
- if (!initializeOnly)
- {
- Console.WriteLine("\n{0}{1}{0}", new string('=', 0x29 - ("Process".Length / 2)), "Process");
- Console.WriteLine("||{0,50}|{1,20:N0}|{2,8}|", "Peak Working Set", currentProcess.PeakWorkingSet64, "bytes");
- Console.WriteLine("||{0,50}|{1,20:N0}|{2,8}|", "Peak Paged Memory", currentProcess.PeakPagedMemorySize64, "bytes");
- Console.WriteLine("||{0,50}|{1,20:N0}|{2,8}|", "Peak Virtual Memory", currentProcess.PeakVirtualMemorySize64, "bytes");
- Console.WriteLine("||{0,50}|{1,20:N0}|{2,8}|", "Peak Privileged Processor Time", currentProcess.PrivilegedProcessorTime.TotalMilliseconds, "ms");
- Console.WriteLine("||{0,50}|{1,20:N0}|{2,8}|", "Peak User Processor Time", currentProcess.UserProcessorTime.TotalMilliseconds, "ms");
- Console.WriteLine("||{0,50}|{1,20:N0}|{2,8}|", "Peak Total Processor Time", currentProcess.TotalProcessorTime.TotalMilliseconds, "ms");
- Console.WriteLine("{0}{0}", new string('=', 0x29));
- }
- string currentInstance = null;
- PerformanceCounterCategory category = new PerformanceCounterCategory("Process");
- foreach (string str2 in category.GetInstanceNames())
- {
- System.Diagnostics.PerformanceCounter counter = new System.Diagnostics.PerformanceCounter(".NET CLR Memory", "Process ID", str2, true);
- try
- {
- if (((int) counter.RawValue) == currentProcess.Id)
- {
- currentInstance = str2;
- break;
- }
- }
- catch (InvalidOperationException)
- {
- }
- finally
- {
- if (counter != null)
- {
- counter.Dispose();
- }
- }
- }
- foreach (PerformanceCounterCategory category2 in PerformanceCounterCategory.GetCategories())
- {
- DumpAllInCategory(currentInstance, category2, initializeOnly);
- }
- }
-
- public static ExitType Execute(string projectFile = null, string[] targets = null, string toolsVersion = null, Dictionary<string, string> globalProperties = null, ILogger[] loggers = null, LoggerVerbosity normal = LoggerVerbosity.Normal)
- {
- ExitType success = ExitType.Success;
- ConsoleCancelEventHandler handler = new ConsoleCancelEventHandler(MSBuildApp.Console_CancelKeyPress);
- try
- {
- Microsoft.Internal.Performance.CodeMarkers.Instance.InitPerformanceDll(CodeMarkerApp.MSBUILDPERF, @"Software\Microsoft\MSBuild\4.0");
- Console.CancelKeyPress += handler;
- VerifyThrowSupportedOS();
- SetConsoleUI();
- ResetBuildState();
- if (Environment.GetEnvironmentVariable("MSBUILDDEBUGONSTART") == "1")
- {
- Debugger.Launch();
- }
-
- if (targets == null)
- {
- targets = new string[0];
- }
-
- if (loggers == null)
- {
- loggers = new ILogger[0];
- }
-
- List<DistributedLoggerRecord> distributedLoggerRecords = new List<DistributedLoggerRecord>();
- bool needToValidateProject = false;
- string schemaFile = null;
- int cpuCount = 1;
- bool enableNodeReuse = true;
- TextWriter preprocessWriter = null;
- bool debugger = false;
- bool detailedSummary = false;
- if (Environment.GetEnvironmentVariable("MSBUILDOLDOM") != "1")
- {
- if (!BuildProject(projectFile, targets, toolsVersion, globalProperties, loggers, normal, distributedLoggerRecords.ToArray(), needToValidateProject, schemaFile, cpuCount, enableNodeReuse, preprocessWriter, debugger, detailedSummary))
- {
- success = ExitType.BuildError;
- }
- return success;
- }
- return OldOMBuildProject(success, projectFile, targets, toolsVersion, globalProperties, loggers, normal, needToValidateProject, schemaFile, cpuCount);
- }
- catch (CommandLineSwitchException exception)
- {
- Console.WriteLine(exception.Message);
- Console.WriteLine();
- ShowHelpPrompt();
- success = ExitType.SwitchError;
- }
- catch (Microsoft.Build.Exceptions.InvalidToolsetDefinitionException exception2)
- {
- Console.WriteLine(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("ConfigurationFailurePrefixNoErrorCode", new object[] { exception2.ErrorCode, exception2.Message }));
- success = ExitType.InitializationError;
- }
- catch (InitializationException exception3)
- {
- Console.WriteLine(exception3.Message);
- success = ExitType.InitializationError;
- }
- catch (LoggerException exception4)
- {
- if (exception4.ErrorCode != null)
- {
- Console.WriteLine(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("LoggerFailurePrefixNoErrorCode", new object[] { exception4.ErrorCode, exception4.Message }));
- }
- else
- {
- Console.WriteLine(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("LoggerFailurePrefixWithErrorCode", new object[] { exception4.Message }));
- }
- if (exception4.InnerException != null)
- {
- Console.WriteLine(exception4.InnerException.ToString());
- }
- success = ExitType.LoggerAbort;
- }
- catch (Microsoft.Build.Exceptions.InternalLoggerException exception5)
- {
- if (!exception5.InitializationException)
- {
- Console.WriteLine("MSBUILD : error " + exception5.ErrorCode + ": " + exception5.Message);
- Console.WriteLine(exception5.InnerException.ToString());
- return ExitType.LoggerFailure;
- }
- Console.WriteLine("MSBUILD : error " + exception5.ErrorCode + ": " + exception5.Message + ((exception5.InnerException != null) ? (" " + exception5.InnerException.Message) : ""));
- return ExitType.InitializationError;
- }
- catch (BuildAbortedException exception6)
- {
- Console.WriteLine("MSBUILD : error " + exception6.ErrorCode + ": " + exception6.Message + ((exception6.InnerException != null) ? (" " + exception6.InnerException.Message) : string.Empty));
- success = ExitType.Unexpected;
- }
- catch (Exception exception7)
- {
- Console.WriteLine("{0}\r\n{1}", Microsoft.Build.Shared.AssemblyResources.GetString("FatalError"), exception7.ToString());
- throw;
- }
- finally
- {
- buildComplete.Set();
- Console.CancelKeyPress -= handler;
- cancelComplete.WaitOne();
- Microsoft.Internal.Performance.CodeMarkers.Instance.UninitializePerformanceDLL(CodeMarkerApp.MSBUILDPERF);
- }
- return success;
- }
-
-
- public static ExitType Execute(string commandLine)
- {
- Microsoft.Build.Shared.ErrorUtilities.VerifyThrowArgumentLength(commandLine, "commandLine");
- ExitType success = ExitType.Success;
- ConsoleCancelEventHandler handler = new ConsoleCancelEventHandler(MSBuildApp.Console_CancelKeyPress);
- try
- {
- Microsoft.Internal.Performance.CodeMarkers.Instance.InitPerformanceDll(CodeMarkerApp.MSBUILDPERF, @"Software\Microsoft\MSBuild\4.0");
- Console.CancelKeyPress += handler;
- VerifyThrowSupportedOS();
- SetConsoleUI();
- ResetBuildState();
- if (Environment.GetEnvironmentVariable("MSBUILDDEBUGONSTART") == "1")
- {
- Debugger.Launch();
- }
- string projectFile = null;
- string[] targets = new string[0];
- string toolsVersion = null;
- Dictionary<string, string> globalProperties = null;
- ILogger[] loggers = new ILogger[0];
- LoggerVerbosity normal = LoggerVerbosity.Normal;
- List<DistributedLoggerRecord> distributedLoggerRecords = null;
- bool needToValidateProject = false;
- string schemaFile = null;
- int cpuCount = 1;
- bool enableNodeReuse = true;
- TextWriter preprocessWriter = null;
- bool debugger = false;
- bool detailedSummary = false;
- if (!ProcessCommandLineSwitches(GatherAllSwitches(commandLine), ref projectFile, ref targets, ref toolsVersion, ref globalProperties, ref loggers, ref normal, ref distributedLoggerRecords, ref needToValidateProject, ref schemaFile, ref cpuCount, ref enableNodeReuse, ref preprocessWriter, ref debugger, ref detailedSummary))
- {
- return success;
- }
- if (Environment.GetEnvironmentVariable("MSBUILDOLDOM") != "1")
- {
- if (!BuildProject(projectFile, targets, toolsVersion, globalProperties, loggers, normal, distributedLoggerRecords.ToArray(), needToValidateProject, schemaFile, cpuCount, enableNodeReuse, preprocessWriter, debugger, detailedSummary))
- {
- success = ExitType.BuildError;
- }
- return success;
- }
- return OldOMBuildProject(success, projectFile, targets, toolsVersion, globalProperties, loggers, normal, needToValidateProject, schemaFile, cpuCount);
- }
- catch (CommandLineSwitchException exception)
- {
- Console.WriteLine(exception.Message);
- Console.WriteLine();
- ShowHelpPrompt();
- success = ExitType.SwitchError;
- }
- catch (Microsoft.Build.Exceptions.InvalidToolsetDefinitionException exception2)
- {
- Console.WriteLine(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("ConfigurationFailurePrefixNoErrorCode", new object[] { exception2.ErrorCode, exception2.Message }));
- success = ExitType.InitializationError;
- }
- catch (InitializationException exception3)
- {
- Console.WriteLine(exception3.Message);
- success = ExitType.InitializationError;
- }
- catch (LoggerException exception4)
- {
- if (exception4.ErrorCode != null)
- {
- Console.WriteLine(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("LoggerFailurePrefixNoErrorCode", new object[] { exception4.ErrorCode, exception4.Message }));
- }
- else
- {
- Console.WriteLine(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("LoggerFailurePrefixWithErrorCode", new object[] { exception4.Message }));
- }
- if (exception4.InnerException != null)
- {
- Console.WriteLine(exception4.InnerException.ToString());
- }
- success = ExitType.LoggerAbort;
- }
- catch (Microsoft.Build.Exceptions.InternalLoggerException exception5)
- {
- if (!exception5.InitializationException)
- {
- Console.WriteLine("MSBUILD : error " + exception5.ErrorCode + ": " + exception5.Message);
- Console.WriteLine(exception5.InnerException.ToString());
- return ExitType.LoggerFailure;
- }
- Console.WriteLine("MSBUILD : error " + exception5.ErrorCode + ": " + exception5.Message + ((exception5.InnerException != null) ? (" " + exception5.InnerException.Message) : ""));
- return ExitType.InitializationError;
- }
- catch (BuildAbortedException exception6)
- {
- Console.WriteLine("MSBUILD : error " + exception6.ErrorCode + ": " + exception6.Message + ((exception6.InnerException != null) ? (" " + exception6.InnerException.Message) : string.Empty));
- success = ExitType.Unexpected;
- }
- catch (Exception exception7)
- {
- Console.WriteLine("{0}\r\n{1}", Microsoft.Build.Shared.AssemblyResources.GetString("FatalError"), exception7.ToString());
- throw;
- }
- finally
- {
- buildComplete.Set();
- Console.CancelKeyPress -= handler;
- cancelComplete.WaitOne();
- Microsoft.Internal.Performance.CodeMarkers.Instance.UninitializePerformanceDLL(CodeMarkerApp.MSBUILDPERF);
- }
- return success;
- }
-
- internal static string ExtractAnyLoggerParameter(string parameters, params string[] parameterNames)
- {
- string[] strArray = parameters.Split(new char[] { ';' });
- string str = null;
- foreach (string str2 in strArray)
- {
- foreach (string str3 in parameterNames)
- {
- if (str2.StartsWith(str3 + "=", StringComparison.OrdinalIgnoreCase) || string.Equals(str3, str2, StringComparison.OrdinalIgnoreCase))
- {
- str = str2;
- }
- }
- }
- return str;
- }
-
- private static string ExtractAnyParameterValue(string parameter)
- {
- string str = null;
- if (!string.IsNullOrEmpty(parameter))
- {
- string[] strArray = parameter.Split(new char[] { '=' });
- str = (strArray.Length > 1) ? strArray[1] : null;
- }
- return str;
- }
-
- internal static string ExtractSwitchParameters(string commandLineArg, string unquotedCommandLineArg, int doubleQuotesRemovedFromArg, string switchName, int switchParameterIndicator)
- {
- string str = null;
- int num2;
- int index = commandLineArg.IndexOf(':');
- string str2 = QuotingUtilities.Unquote(commandLineArg.Substring(0, index), out num2);
- Microsoft.Build.Shared.ErrorUtilities.VerifyThrow(switchName == str2.Substring(1), "The switch name extracted from either the partially or completely unquoted arg should be the same.");
- Microsoft.Build.Shared.ErrorUtilities.VerifyThrow(doubleQuotesRemovedFromArg >= num2, "The name portion of the switch cannot contain more quoting than the arg itself.");
- if ((num2 % 2) == 0)
- {
- str = commandLineArg.Substring(index);
- }
- else
- {
- int num3 = commandLineArg.IndexOf('"', index + 1);
- if (((doubleQuotesRemovedFromArg - num2) <= 1) && ((num3 == -1) || (num3 == (commandLineArg.Length - 1))))
- {
- str = unquotedCommandLineArg.Substring(switchParameterIndicator);
- }
- else
- {
- str = ":\"" + commandLineArg.Substring(index + 1);
- }
- }
- Microsoft.Build.Shared.ErrorUtilities.VerifyThrow(str != null, "We must be able to extract the switch parameters.");
- return str;
- }
-
- private static CommandLineSwitches GatherAllSwitches(string commandLine)
- {
- ArrayList commandLineArgs = QuotingUtilities.SplitUnquoted(commandLine, new char[0]);
- CommandLineSwitches commandLineSwitches = new CommandLineSwitches();
- GatherCommandLineSwitches(commandLineArgs, commandLineSwitches);
- return GatherAutoResponseFileSwitches(commandLineSwitches);
- }
-
- private static CommandLineSwitches GatherAutoResponseFileSwitches(CommandLineSwitches commandLineSwitches)
- {
- CommandLineSwitches switches = commandLineSwitches;
- if (!commandLineSwitches[CommandLineSwitches.ParameterlessSwitch.NoAutoResponse])
- {
- string path = Path.Combine(exePath, "MSBuild.rsp");
- if (!File.Exists(path))
- {
- return switches;
- }
- switches = new CommandLineSwitches();
- GatherResponseFileSwitch("@" + path, switches);
- if (switches[CommandLineSwitches.ParameterlessSwitch.NoAutoResponse])
- {
- switches.SetSwitchError("CannotAutoDisableAutoResponseFile", switches.GetParameterlessSwitchCommandLineArg(CommandLineSwitches.ParameterlessSwitch.NoAutoResponse));
- }
- if (switches.HaveAnySwitchesBeenSet())
- {
- usingSwitchesFromAutoResponseFile = true;
- }
- switches.Append(commandLineSwitches);
- }
- return switches;
- }
-
- internal static void GatherCommandLineSwitches(ArrayList commandLineArgs, CommandLineSwitches commandLineSwitches)
- {
- foreach (string str in commandLineArgs)
- {
- int num;
- string unquotedCommandLineArg = QuotingUtilities.Unquote(str, out num);
- if (unquotedCommandLineArg.Length > 0)
- {
- string str3;
- string str4;
- CommandLineSwitches.ParameterlessSwitch switch2;
- string str5;
- if (unquotedCommandLineArg.StartsWith("@", StringComparison.Ordinal))
- {
- GatherResponseFileSwitch(unquotedCommandLineArg, commandLineSwitches);
- continue;
- }
- if (!unquotedCommandLineArg.StartsWith("-", StringComparison.Ordinal) && !unquotedCommandLineArg.StartsWith("/", StringComparison.Ordinal))
- {
- str3 = null;
- str4 = ":" + str;
- }
- else
- {
- int index = unquotedCommandLineArg.IndexOf(':');
- if (index == -1)
- {
- str3 = unquotedCommandLineArg.Substring(1);
- str4 = string.Empty;
- }
- else
- {
- str3 = unquotedCommandLineArg.Substring(1, index - 1);
- str4 = ExtractSwitchParameters(str, unquotedCommandLineArg, num, str3, index);
- }
- }
- if (string.IsNullOrEmpty(str4) && (string.Equals(str3, "m", StringComparison.OrdinalIgnoreCase) || string.Equals(str3, "maxcpucount", StringComparison.OrdinalIgnoreCase)))
- {
- int processorCount = Environment.ProcessorCount;
- str4 = ":" + processorCount;
- }
- if (CommandLineSwitches.IsParameterlessSwitch(str3, out switch2, out str5))
- {
- GatherParameterlessCommandLineSwitch(commandLineSwitches, switch2, str4, str5, unquotedCommandLineArg);
- }
- else
- {
- CommandLineSwitches.ParameterizedSwitch switch3;
- bool flag;
- string str6;
- bool flag2;
- if (CommandLineSwitches.IsParameterizedSwitch(str3, out switch3, out str5, out flag, out str6, out flag2))
- {
- GatherParameterizedCommandLineSwitch(commandLineSwitches, switch3, str4, str5, flag, str6, flag2, unquotedCommandLineArg);
- continue;
- }
- commandLineSwitches.SetUnknownSwitchError(unquotedCommandLineArg);
- }
- }
- }
- }
-
- private static void GatherParameterizedCommandLineSwitch(CommandLineSwitches commandLineSwitches, CommandLineSwitches.ParameterizedSwitch parameterizedSwitch, string switchParameters, string duplicateSwitchErrorMessage, bool multipleParametersAllowed, string missingParametersErrorMessage, bool unquoteParameters, string unquotedCommandLineArg)
- {
- if ((switchParameters.Length > 1) || (missingParametersErrorMessage == null))
- {
- if (commandLineSwitches.IsParameterizedSwitchSet(parameterizedSwitch) && (duplicateSwitchErrorMessage != null))
- {
- commandLineSwitches.SetSwitchError(duplicateSwitchErrorMessage, unquotedCommandLineArg);
- }
- else
- {
- if (switchParameters.Length > 0)
- {
- switchParameters = switchParameters.Substring(1);
- }
- if (!commandLineSwitches.SetParameterizedSwitch(parameterizedSwitch, unquotedCommandLineArg, switchParameters, multipleParametersAllowed, unquoteParameters) && (missingParametersErrorMessage != null))
- {
- commandLineSwitches.SetSwitchError(missingParametersErrorMessage, unquotedCommandLineArg);
- }
- }
- }
- else
- {
- commandLineSwitches.SetSwitchError(missingParametersErrorMessage, unquotedCommandLineArg);
- }
- }
-
- private static void GatherParameterlessCommandLineSwitch(CommandLineSwitches commandLineSwitches, CommandLineSwitches.ParameterlessSwitch parameterlessSwitch, string switchParameters, string duplicateSwitchErrorMessage, string unquotedCommandLineArg)
- {
- if (switchParameters.Length == 0)
- {
- if (!commandLineSwitches.IsParameterlessSwitchSet(parameterlessSwitch) || (duplicateSwitchErrorMessage == null))
- {
- commandLineSwitches.SetParameterlessSwitch(parameterlessSwitch, unquotedCommandLineArg);
- }
- else
- {
- commandLineSwitches.SetSwitchError(duplicateSwitchErrorMessage, unquotedCommandLineArg);
- }
- }
- else
- {
- commandLineSwitches.SetUnexpectedParametersError(unquotedCommandLineArg);
- }
- }
-
- private static void GatherResponseFileSwitch(string unquotedCommandLineArg, CommandLineSwitches commandLineSwitches)
- {
- try
- {
- string path = unquotedCommandLineArg.Substring(1);
- if (path.Length == 0)
- {
- commandLineSwitches.SetSwitchError("MissingResponseFileError", unquotedCommandLineArg);
- }
- else if (!File.Exists(path))
- {
- commandLineSwitches.SetParameterError("ResponseFileNotFoundError", unquotedCommandLineArg);
- }
- else
- {
- path = Path.GetFullPath(path);
- bool flag = false;
- foreach (string str2 in includedResponseFiles)
- {
- if (string.Compare(path, str2, StringComparison.OrdinalIgnoreCase) == 0)
- {
- commandLineSwitches.SetParameterError("RepeatedResponseFileError", unquotedCommandLineArg);
- flag = true;
- break;
- }
- }
- if (!flag)
- {
- ArrayList list;
- includedResponseFiles.Add(path);
- using (StreamReader reader = new StreamReader(path, Encoding.Default))
- {
- list = new ArrayList();
- while (reader.Peek() != -1)
- {
- string name = reader.ReadLine().TrimStart(new char[0]);
- if (!name.StartsWith("#", StringComparison.Ordinal))
- {
- list.AddRange(QuotingUtilities.SplitUnquoted(Environment.ExpandEnvironmentVariables(name), new char[0]));
- }
- }
- }
- GatherCommandLineSwitches(list, commandLineSwitches);
- }
- }
- }
- catch (NotSupportedException exception)
- {
- commandLineSwitches.SetParameterError("ReadResponseFileError", unquotedCommandLineArg, exception);
- }
- catch (SecurityException exception2)
- {
- commandLineSwitches.SetParameterError("ReadResponseFileError", unquotedCommandLineArg, exception2);
- }
- catch (UnauthorizedAccessException exception3)
- {
- commandLineSwitches.SetParameterError("ReadResponseFileError", unquotedCommandLineArg, exception3);
- }
- catch (IOException exception4)
- {
- commandLineSwitches.SetParameterError("ReadResponseFileError", unquotedCommandLineArg, exception4);
- }
- }
-
- private static string GetFriendlyCounterType(PerformanceCounterType type, string name)
- {
- if (name.IndexOf("bytes", StringComparison.OrdinalIgnoreCase) != -1)
- {
- return "bytes";
- }
- if (name.IndexOf("threads", StringComparison.OrdinalIgnoreCase) != -1)
- {
- return "threads";
- }
- switch (type)
- {
- case PerformanceCounterType.NumberOfItems64:
- case PerformanceCounterType.CounterDelta32:
- case PerformanceCounterType.CounterDelta64:
- case PerformanceCounterType.NumberOfItemsHEX32:
- case PerformanceCounterType.NumberOfItemsHEX64:
- case PerformanceCounterType.NumberOfItems32:
- case PerformanceCounterType.SampleCounter:
- case PerformanceCounterType.CountPerTimeInterval32:
- case PerformanceCounterType.CountPerTimeInterval64:
- case PerformanceCounterType.CounterTimer:
- case PerformanceCounterType.RateOfCountsPerSecond32:
- case PerformanceCounterType.RateOfCountsPerSecond64:
- case PerformanceCounterType.CounterMultiTimer:
- case PerformanceCounterType.CounterTimerInverse:
- case PerformanceCounterType.CounterMultiTimerInverse:
- case PerformanceCounterType.AverageCount64:
- return "#";
-
- case PerformanceCounterType.RawFraction:
- case PerformanceCounterType.CounterMultiTimer100Ns:
- case PerformanceCounterType.SampleFraction:
- case PerformanceCounterType.CounterMultiTimer100NsInverse:
- return "%";
-
- case PerformanceCounterType.Timer100NsInverse:
- case PerformanceCounterType.Timer100Ns:
- return "100ns";…
Large files files are truncated, but you can click here to view the full file