PageRenderTime 58ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/MSBuild/Microsoft/Build/CommandLine/MSBuildApp.cs

#
C# | 1572 lines | 1556 code | 16 blank | 0 comment | 114 complexity | 6afbea180ca6202e4e0a75006a7993f9 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0
  1. namespace Microsoft.Build.CommandLine
  2. {
  3. using Microsoft.Build.BuildEngine;
  4. using Microsoft.Build.Evaluation;
  5. using Microsoft.Build.Exceptions;
  6. using Microsoft.Build.Execution;
  7. using Microsoft.Build.Framework;
  8. using Microsoft.Build.Logging;
  9. using Microsoft.Build.Shared;
  10. using Microsoft.Internal.Performance;
  11. using System;
  12. using System.Collections;
  13. using System.Collections.Generic;
  14. using System.Configuration;
  15. using System.Diagnostics;
  16. using System.Globalization;
  17. using System.IO;
  18. using System.Reflection;
  19. using System.Runtime.CompilerServices;
  20. using System.Runtime.InteropServices;
  21. using System.Security;
  22. using System.Text;
  23. using System.Threading;
  24. public static class MSBuildApp
  25. {
  26. private static BuildSubmission activeBuild;
  27. private const string autoResponseFileName = "MSBuild.rsp";
  28. private static ManualResetEvent buildComplete = new ManualResetEvent(false);
  29. private static object buildLock = new object();
  30. private static ManualResetEvent cancelComplete = new ManualResetEvent(true);
  31. private static readonly string exePath;
  32. private static ArrayList includedResponseFiles;
  33. private static bool initialized;
  34. private const string msbuildLogFileName = "msbuild.log";
  35. private static readonly char[] propertyValueSeparator = new char[] { '=' };
  36. private static int receivedCancel;
  37. internal static bool usingSwitchesFromAutoResponseFile = false;
  38. private static readonly char[] wildcards = new char[] { '*', '?' };
  39. static MSBuildApp()
  40. {
  41. try
  42. {
  43. exePath = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath);
  44. initialized = true;
  45. }
  46. catch (TypeInitializationException exception)
  47. {
  48. if ((exception.InnerException == null) || (exception.InnerException.GetType() != typeof(ConfigurationErrorsException)))
  49. {
  50. throw;
  51. }
  52. HandleConfigurationException(exception);
  53. }
  54. catch (ConfigurationException exception2)
  55. {
  56. HandleConfigurationException(exception2);
  57. }
  58. }
  59. internal static string AggregateParameters(string anyPrefixingParameter, string[] parametersToAggregate)
  60. {
  61. for (int i = 0; i < parametersToAggregate.Length; i++)
  62. {
  63. parametersToAggregate[i] = parametersToAggregate[i].Trim(new char[] { ';' });
  64. }
  65. string str = anyPrefixingParameter ?? string.Empty;
  66. return (str + string.Join(";", parametersToAggregate));
  67. }
  68. 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)
  69. {
  70. if (string.Equals(Path.GetExtension(projectFile), ".vcproj", StringComparison.OrdinalIgnoreCase) || string.Equals(Path.GetExtension(projectFile), ".dsp", StringComparison.OrdinalIgnoreCase))
  71. {
  72. InitializationException.Throw(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("ProjectUpgradeNeededToVcxProj", new object[] { projectFile }), null);
  73. }
  74. bool flag = false;
  75. ProjectCollection projectCollection = null;
  76. bool onlyLogCriticalEvents = false;
  77. try
  78. {
  79. List<ForwardingLoggerRecord> list = new List<ForwardingLoggerRecord>();
  80. foreach (DistributedLoggerRecord record in distributedLoggerRecords)
  81. {
  82. list.Add(new ForwardingLoggerRecord(record.CentralLogger, record.ForwardingLoggerDescription));
  83. }
  84. 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)))
  85. {
  86. Type type = loggers[0].GetType();
  87. Type type2 = typeof(Microsoft.Build.Logging.ConsoleLogger);
  88. if (type == type2)
  89. {
  90. onlyLogCriticalEvents = true;
  91. }
  92. }
  93. projectCollection = new ProjectCollection(globalProperties, loggers, null, Microsoft.Build.Evaluation.ToolsetDefinitionLocations.Registry | Microsoft.Build.Evaluation.ToolsetDefinitionLocations.ConfigurationFile, cpuCount, onlyLogCriticalEvents);
  94. if (debugger)
  95. {
  96. Environment.SetEnvironmentVariable("MSBUILDDEBUGGING", "1");
  97. }
  98. if ((toolsVersion != null) && !projectCollection.ContainsToolset(toolsVersion))
  99. {
  100. ThrowInvalidToolsVersionInitializationException(projectCollection.Toolsets, toolsVersion);
  101. }
  102. if (needToValidateProject && !Microsoft.Build.Shared.FileUtilities.IsSolutionFilename(projectFile))
  103. {
  104. Microsoft.Build.Evaluation.Project project = projectCollection.LoadProject(projectFile, globalProperties, toolsVersion);
  105. Microsoft.Build.Evaluation.Toolset toolset = projectCollection.GetToolset((toolsVersion == null) ? project.ToolsVersion : toolsVersion);
  106. if (toolset == null)
  107. {
  108. ThrowInvalidToolsVersionInitializationException(projectCollection.Toolsets, project.ToolsVersion);
  109. }
  110. Microsoft.Build.CommandLine.ProjectSchemaValidationHandler.VerifyProjectSchema(projectFile, schemaFile, toolset.ToolsPath);
  111. projectCollection.UnloadProject(project);
  112. }
  113. if ((preprocessWriter != null) && !Microsoft.Build.Shared.FileUtilities.IsSolutionFilename(projectFile))
  114. {
  115. Microsoft.Build.Evaluation.Project project2 = projectCollection.LoadProject(projectFile, globalProperties, toolsVersion);
  116. project2.SaveLogicalProject(preprocessWriter);
  117. projectCollection.UnloadProject(project2);
  118. return flag;
  119. }
  120. BuildRequestData requestData = new BuildRequestData(projectFile, globalProperties, toolsVersion, targets, null);
  121. BuildParameters parameters = new BuildParameters(projectCollection);
  122. if (!string.Equals(Environment.GetEnvironmentVariable("MSBUILDLOGASYNC"), "1", StringComparison.Ordinal))
  123. {
  124. parameters.UseSynchronousLogging = true;
  125. }
  126. parameters.EnableNodeReuse = enableNodeReuse;
  127. parameters.NodeExeLocation = Assembly.GetExecutingAssembly().Location;
  128. parameters.MaxNodeCount = cpuCount;
  129. parameters.Loggers = projectCollection.Loggers;
  130. parameters.ForwardingLoggers = list;
  131. parameters.ToolsetDefinitionLocations = Microsoft.Build.Evaluation.ToolsetDefinitionLocations.Registry | Microsoft.Build.Evaluation.ToolsetDefinitionLocations.ConfigurationFile;
  132. parameters.DetailedSummary = detailedSummary;
  133. if (!string.IsNullOrEmpty(toolsVersion))
  134. {
  135. parameters.DefaultToolsVersion = toolsVersion;
  136. }
  137. string environmentVariable = Environment.GetEnvironmentVariable("MSBUILDMEMORYUSELIMIT");
  138. if (!string.IsNullOrEmpty(environmentVariable))
  139. {
  140. parameters.MemoryUseLimit = Convert.ToInt32(environmentVariable, CultureInfo.InvariantCulture);
  141. if (parameters.MemoryUseLimit < parameters.MaxNodeCount)
  142. {
  143. parameters.MemoryUseLimit = parameters.MaxNodeCount;
  144. }
  145. }
  146. BuildManager defaultBuildManager = BuildManager.DefaultBuildManager;
  147. Microsoft.Build.Execution.BuildResult result = null;
  148. defaultBuildManager.BeginBuild(parameters);
  149. Exception exception = null;
  150. try
  151. {
  152. try
  153. {
  154. lock (buildLock)
  155. {
  156. activeBuild = defaultBuildManager.PendBuildRequest(requestData);
  157. }
  158. result = activeBuild.Execute();
  159. }
  160. finally
  161. {
  162. defaultBuildManager.EndBuild();
  163. }
  164. }
  165. catch (Exception exception2)
  166. {
  167. exception = exception2;
  168. flag = false;
  169. }
  170. if ((result != null) && (exception == null))
  171. {
  172. flag = result.OverallResult == BuildResultCode.Success;
  173. exception = result.Exception;
  174. }
  175. if (exception != null)
  176. {
  177. flag = false;
  178. if (!(exception.GetType() != typeof(Microsoft.Build.Exceptions.InvalidProjectFileException)))
  179. {
  180. return flag;
  181. }
  182. if ((exception.GetType() == typeof(LoggerException)) || (exception.GetType() == typeof(Microsoft.Build.Exceptions.InternalLoggerException)))
  183. {
  184. throw exception;
  185. }
  186. if (!(exception.GetType() == typeof(BuildAbortedException)))
  187. {
  188. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("FatalError"));
  189. Console.WriteLine(exception.ToString());
  190. Console.WriteLine();
  191. throw exception;
  192. }
  193. }
  194. return flag;
  195. }
  196. catch (Microsoft.Build.Exceptions.InvalidProjectFileException exception3)
  197. {
  198. Microsoft.Build.Shared.ErrorUtilities.VerifyThrow(exception3.HasBeenLogged, "Should have been logged");
  199. flag = false;
  200. }
  201. finally
  202. {
  203. Microsoft.Build.Shared.FileUtilities.ClearCacheDirectory();
  204. if (projectCollection != null)
  205. {
  206. projectCollection.Dispose();
  207. }
  208. }
  209. return flag;
  210. }
  211. [MethodImpl(MethodImplOptions.NoInlining)]
  212. private static bool BuildProjectWithOldOM(string projectFile, string[] targets, string toolsVersion, BuildPropertyGroup propertyBag, ILogger[] loggers, LoggerVerbosity verbosity, DistributedLoggerRecord[] distributedLoggerRecords, bool needToValidateProject, string schemaFile, int cpuCount)
  213. {
  214. string directoryName = Path.GetDirectoryName(Assembly.GetAssembly(typeof(MSBuildApp)).Location);
  215. string localNodeProviderParameters = "msbuildlocation=" + directoryName + ";nodereuse=false";
  216. Engine engine = new Engine(propertyBag, Microsoft.Build.BuildEngine.ToolsetDefinitionLocations.Registry | Microsoft.Build.BuildEngine.ToolsetDefinitionLocations.ConfigurationFile, cpuCount, localNodeProviderParameters);
  217. bool flag = false;
  218. try
  219. {
  220. foreach (ILogger logger in loggers)
  221. {
  222. engine.RegisterLogger(logger);
  223. }
  224. 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)))
  225. {
  226. Type type = loggers[0].GetType();
  227. Type type2 = typeof(Microsoft.Build.Logging.ConsoleLogger);
  228. if (type == type2)
  229. {
  230. engine.OnlyLogCriticalEvents = true;
  231. }
  232. }
  233. Microsoft.Build.BuildEngine.Project project = null;
  234. try
  235. {
  236. project = new Microsoft.Build.BuildEngine.Project(engine, toolsVersion);
  237. }
  238. catch (InvalidOperationException exception)
  239. {
  240. InitializationException.Throw("InvalidToolsVersionError", toolsVersion, exception, false);
  241. }
  242. project.IsValidated = needToValidateProject;
  243. project.SchemaFile = schemaFile;
  244. project.Load(projectFile);
  245. flag = engine.BuildProject(project, targets);
  246. }
  247. catch (Microsoft.Build.Exceptions.InvalidProjectFileException)
  248. {
  249. }
  250. finally
  251. {
  252. engine.Shutdown();
  253. }
  254. return flag;
  255. }
  256. private static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
  257. {
  258. if (e.SpecialKey == ConsoleSpecialKey.ControlBreak)
  259. {
  260. e.Cancel = false;
  261. }
  262. else
  263. {
  264. e.Cancel = true;
  265. if (Interlocked.CompareExchange(ref receivedCancel, 1, 0) != 1)
  266. {
  267. Console.WriteLine(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("AbortingBuild", new object[0]));
  268. WaitCallback callBack = delegate {
  269. cancelComplete.Reset();
  270. if (buildComplete.WaitOne(0, false))
  271. {
  272. cancelComplete.Set();
  273. }
  274. else
  275. {
  276. BuildSubmission activeBuild = null;
  277. lock (buildLock)
  278. {
  279. activeBuild = MSBuildApp.activeBuild;
  280. }
  281. if (activeBuild != null)
  282. {
  283. BuildManager.DefaultBuildManager.CancelAllSubmissions();
  284. buildComplete.WaitOne();
  285. }
  286. cancelComplete.Set();
  287. }
  288. };
  289. ThreadPool.QueueUserWorkItem(callBack);
  290. }
  291. }
  292. }
  293. private static ILogger CreateAndConfigureLogger(Microsoft.Build.Logging.LoggerDescription loggerDescription, LoggerVerbosity verbosity, string unquotedParameter)
  294. {
  295. ILogger logger = null;
  296. try
  297. {
  298. logger = loggerDescription.CreateLogger();
  299. if (logger == null)
  300. {
  301. InitializationException.VerifyThrow(logger != null, "LoggerNotFoundError", unquotedParameter);
  302. }
  303. }
  304. catch (IOException exception)
  305. {
  306. InitializationException.Throw("LoggerCreationError", unquotedParameter, exception, false);
  307. }
  308. catch (BadImageFormatException exception2)
  309. {
  310. InitializationException.Throw("LoggerCreationError", unquotedParameter, exception2, false);
  311. }
  312. catch (SecurityException exception3)
  313. {
  314. InitializationException.Throw("LoggerCreationError", unquotedParameter, exception3, false);
  315. }
  316. catch (ReflectionTypeLoadException exception4)
  317. {
  318. InitializationException.Throw("LoggerCreationError", unquotedParameter, exception4, false);
  319. }
  320. catch (MemberAccessException exception5)
  321. {
  322. InitializationException.Throw("LoggerCreationError", unquotedParameter, exception5, false);
  323. }
  324. catch (TargetInvocationException exception6)
  325. {
  326. InitializationException.Throw("LoggerFatalError", unquotedParameter, exception6.InnerException, true);
  327. }
  328. try
  329. {
  330. logger.Verbosity = verbosity;
  331. if (loggerDescription.LoggerSwitchParameters != null)
  332. {
  333. logger.Parameters = loggerDescription.LoggerSwitchParameters;
  334. }
  335. }
  336. catch (LoggerException)
  337. {
  338. throw;
  339. }
  340. catch (Exception exception7)
  341. {
  342. InitializationException.Throw("LoggerFatalError", unquotedParameter, exception7, true);
  343. }
  344. return logger;
  345. }
  346. private static DistributedLoggerRecord CreateForwardingLoggerRecord(ILogger logger, string loggerParameters, LoggerVerbosity defaultVerbosity)
  347. {
  348. string str2 = ExtractAnyParameterValue(ExtractAnyLoggerParameter(loggerParameters, new string[] { "verbosity", "v" }));
  349. LoggerVerbosity verbosity = defaultVerbosity;
  350. if (!string.IsNullOrEmpty(str2))
  351. {
  352. verbosity = ProcessVerbositySwitch(str2);
  353. }
  354. Assembly assembly = Assembly.GetAssembly(typeof(ProjectCollection));
  355. string loggerClassName = "Microsoft.Build.Logging.ConfigurableForwardingLogger";
  356. string fullName = assembly.GetName().FullName;
  357. return new DistributedLoggerRecord(logger, new Microsoft.Build.Logging.LoggerDescription(loggerClassName, fullName, null, loggerParameters, verbosity));
  358. }
  359. private static void DisplayCopyrightMessage()
  360. {
  361. Console.WriteLine(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("CopyrightMessage", new object[] { ProjectCollection.Version.ToString(), Environment.Version.ToString() }));
  362. }
  363. private static void DumpAllInCategory(string currentInstance, PerformanceCounterCategory category, bool initializeOnly)
  364. {
  365. if (category.CategoryName.IndexOf("remoting", StringComparison.OrdinalIgnoreCase) == -1)
  366. {
  367. System.Diagnostics.PerformanceCounter[] counters;
  368. try
  369. {
  370. counters = category.GetCounters(currentInstance);
  371. }
  372. catch (InvalidOperationException)
  373. {
  374. return;
  375. }
  376. if (!initializeOnly)
  377. {
  378. Console.WriteLine("\n{0}{1}{0}", new string('=', 0x29 - (category.CategoryName.Length / 2)), category.CategoryName);
  379. }
  380. foreach (System.Diagnostics.PerformanceCounter counter in counters)
  381. {
  382. DumpCounter(counter, initializeOnly);
  383. }
  384. if (!initializeOnly)
  385. {
  386. Console.WriteLine("{0}{0}", new string('=', 0x29));
  387. }
  388. }
  389. }
  390. private static void DumpCounter(System.Diagnostics.PerformanceCounter counter, bool initializeOnly)
  391. {
  392. if (counter.CounterName.IndexOf("not displayed", StringComparison.OrdinalIgnoreCase) == -1)
  393. {
  394. float num = counter.NextValue();
  395. if (!initializeOnly)
  396. {
  397. string friendlyCounterType = GetFriendlyCounterType(counter.CounterType, counter.CounterName);
  398. string format = (num < 10f) ? "{0,20:N2}" : "{0,20:N0}";
  399. string str3 = string.Format(CultureInfo.CurrentCulture, format, new object[] { num });
  400. Console.WriteLine("||{0,50}|{1}|{2,8}|", counter.CounterName, str3, friendlyCounterType);
  401. }
  402. }
  403. }
  404. private static void DumpCounters(bool initializeOnly)
  405. {
  406. Process currentProcess = Process.GetCurrentProcess();
  407. if (!initializeOnly)
  408. {
  409. Console.WriteLine("\n{0}{1}{0}", new string('=', 0x29 - ("Process".Length / 2)), "Process");
  410. Console.WriteLine("||{0,50}|{1,20:N0}|{2,8}|", "Peak Working Set", currentProcess.PeakWorkingSet64, "bytes");
  411. Console.WriteLine("||{0,50}|{1,20:N0}|{2,8}|", "Peak Paged Memory", currentProcess.PeakPagedMemorySize64, "bytes");
  412. Console.WriteLine("||{0,50}|{1,20:N0}|{2,8}|", "Peak Virtual Memory", currentProcess.PeakVirtualMemorySize64, "bytes");
  413. Console.WriteLine("||{0,50}|{1,20:N0}|{2,8}|", "Peak Privileged Processor Time", currentProcess.PrivilegedProcessorTime.TotalMilliseconds, "ms");
  414. Console.WriteLine("||{0,50}|{1,20:N0}|{2,8}|", "Peak User Processor Time", currentProcess.UserProcessorTime.TotalMilliseconds, "ms");
  415. Console.WriteLine("||{0,50}|{1,20:N0}|{2,8}|", "Peak Total Processor Time", currentProcess.TotalProcessorTime.TotalMilliseconds, "ms");
  416. Console.WriteLine("{0}{0}", new string('=', 0x29));
  417. }
  418. string currentInstance = null;
  419. PerformanceCounterCategory category = new PerformanceCounterCategory("Process");
  420. foreach (string str2 in category.GetInstanceNames())
  421. {
  422. System.Diagnostics.PerformanceCounter counter = new System.Diagnostics.PerformanceCounter(".NET CLR Memory", "Process ID", str2, true);
  423. try
  424. {
  425. if (((int) counter.RawValue) == currentProcess.Id)
  426. {
  427. currentInstance = str2;
  428. break;
  429. }
  430. }
  431. catch (InvalidOperationException)
  432. {
  433. }
  434. finally
  435. {
  436. if (counter != null)
  437. {
  438. counter.Dispose();
  439. }
  440. }
  441. }
  442. foreach (PerformanceCounterCategory category2 in PerformanceCounterCategory.GetCategories())
  443. {
  444. DumpAllInCategory(currentInstance, category2, initializeOnly);
  445. }
  446. }
  447. public static ExitType Execute(string commandLine)
  448. {
  449. Microsoft.Build.Shared.ErrorUtilities.VerifyThrowArgumentLength(commandLine, "commandLine");
  450. ExitType success = ExitType.Success;
  451. ConsoleCancelEventHandler handler = new ConsoleCancelEventHandler(MSBuildApp.Console_CancelKeyPress);
  452. try
  453. {
  454. Microsoft.Internal.Performance.CodeMarkers.Instance.InitPerformanceDll(CodeMarkerApp.MSBUILDPERF, @"Software\Microsoft\MSBuild\4.0");
  455. Console.CancelKeyPress += handler;
  456. VerifyThrowSupportedOS();
  457. SetConsoleUI();
  458. ResetBuildState();
  459. if (Environment.GetEnvironmentVariable("MSBUILDDEBUGONSTART") == "1")
  460. {
  461. Debugger.Launch();
  462. }
  463. string projectFile = null;
  464. string[] targets = new string[0];
  465. string toolsVersion = null;
  466. Dictionary<string, string> globalProperties = null;
  467. ILogger[] loggers = new ILogger[0];
  468. LoggerVerbosity normal = LoggerVerbosity.Normal;
  469. List<DistributedLoggerRecord> distributedLoggerRecords = null;
  470. bool needToValidateProject = false;
  471. string schemaFile = null;
  472. int cpuCount = 1;
  473. bool enableNodeReuse = true;
  474. TextWriter preprocessWriter = null;
  475. bool debugger = false;
  476. bool detailedSummary = false;
  477. 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))
  478. {
  479. return success;
  480. }
  481. if (Environment.GetEnvironmentVariable("MSBUILDOLDOM") != "1")
  482. {
  483. if (!BuildProject(projectFile, targets, toolsVersion, globalProperties, loggers, normal, distributedLoggerRecords.ToArray(), needToValidateProject, schemaFile, cpuCount, enableNodeReuse, preprocessWriter, debugger, detailedSummary))
  484. {
  485. success = ExitType.BuildError;
  486. }
  487. return success;
  488. }
  489. return OldOMBuildProject(success, projectFile, targets, toolsVersion, globalProperties, loggers, normal, needToValidateProject, schemaFile, cpuCount);
  490. }
  491. catch (CommandLineSwitchException exception)
  492. {
  493. Console.WriteLine(exception.Message);
  494. Console.WriteLine();
  495. ShowHelpPrompt();
  496. success = ExitType.SwitchError;
  497. }
  498. catch (Microsoft.Build.Exceptions.InvalidToolsetDefinitionException exception2)
  499. {
  500. Console.WriteLine(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("ConfigurationFailurePrefixNoErrorCode", new object[] { exception2.ErrorCode, exception2.Message }));
  501. success = ExitType.InitializationError;
  502. }
  503. catch (InitializationException exception3)
  504. {
  505. Console.WriteLine(exception3.Message);
  506. success = ExitType.InitializationError;
  507. }
  508. catch (LoggerException exception4)
  509. {
  510. if (exception4.ErrorCode != null)
  511. {
  512. Console.WriteLine(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("LoggerFailurePrefixNoErrorCode", new object[] { exception4.ErrorCode, exception4.Message }));
  513. }
  514. else
  515. {
  516. Console.WriteLine(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("LoggerFailurePrefixWithErrorCode", new object[] { exception4.Message }));
  517. }
  518. if (exception4.InnerException != null)
  519. {
  520. Console.WriteLine(exception4.InnerException.ToString());
  521. }
  522. success = ExitType.LoggerAbort;
  523. }
  524. catch (Microsoft.Build.Exceptions.InternalLoggerException exception5)
  525. {
  526. if (!exception5.InitializationException)
  527. {
  528. Console.WriteLine("MSBUILD : error " + exception5.ErrorCode + ": " + exception5.Message);
  529. Console.WriteLine(exception5.InnerException.ToString());
  530. return ExitType.LoggerFailure;
  531. }
  532. Console.WriteLine("MSBUILD : error " + exception5.ErrorCode + ": " + exception5.Message + ((exception5.InnerException != null) ? (" " + exception5.InnerException.Message) : ""));
  533. return ExitType.InitializationError;
  534. }
  535. catch (BuildAbortedException exception6)
  536. {
  537. Console.WriteLine("MSBUILD : error " + exception6.ErrorCode + ": " + exception6.Message + ((exception6.InnerException != null) ? (" " + exception6.InnerException.Message) : string.Empty));
  538. success = ExitType.Unexpected;
  539. }
  540. catch (Exception exception7)
  541. {
  542. Console.WriteLine("{0}\r\n{1}", Microsoft.Build.Shared.AssemblyResources.GetString("FatalError"), exception7.ToString());
  543. throw;
  544. }
  545. finally
  546. {
  547. buildComplete.Set();
  548. Console.CancelKeyPress -= handler;
  549. cancelComplete.WaitOne();
  550. Microsoft.Internal.Performance.CodeMarkers.Instance.UninitializePerformanceDLL(CodeMarkerApp.MSBUILDPERF);
  551. }
  552. return success;
  553. }
  554. internal static string ExtractAnyLoggerParameter(string parameters, params string[] parameterNames)
  555. {
  556. string[] strArray = parameters.Split(new char[] { ';' });
  557. string str = null;
  558. foreach (string str2 in strArray)
  559. {
  560. foreach (string str3 in parameterNames)
  561. {
  562. if (str2.StartsWith(str3 + "=", StringComparison.OrdinalIgnoreCase) || string.Equals(str3, str2, StringComparison.OrdinalIgnoreCase))
  563. {
  564. str = str2;
  565. }
  566. }
  567. }
  568. return str;
  569. }
  570. private static string ExtractAnyParameterValue(string parameter)
  571. {
  572. string str = null;
  573. if (!string.IsNullOrEmpty(parameter))
  574. {
  575. string[] strArray = parameter.Split(new char[] { '=' });
  576. str = (strArray.Length > 1) ? strArray[1] : null;
  577. }
  578. return str;
  579. }
  580. internal static string ExtractSwitchParameters(string commandLineArg, string unquotedCommandLineArg, int doubleQuotesRemovedFromArg, string switchName, int switchParameterIndicator)
  581. {
  582. string str = null;
  583. int num2;
  584. int index = commandLineArg.IndexOf(':');
  585. string str2 = QuotingUtilities.Unquote(commandLineArg.Substring(0, index), out num2);
  586. 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.");
  587. Microsoft.Build.Shared.ErrorUtilities.VerifyThrow(doubleQuotesRemovedFromArg >= num2, "The name portion of the switch cannot contain more quoting than the arg itself.");
  588. if ((num2 % 2) == 0)
  589. {
  590. str = commandLineArg.Substring(index);
  591. }
  592. else
  593. {
  594. int num3 = commandLineArg.IndexOf('"', index + 1);
  595. if (((doubleQuotesRemovedFromArg - num2) <= 1) && ((num3 == -1) || (num3 == (commandLineArg.Length - 1))))
  596. {
  597. str = unquotedCommandLineArg.Substring(switchParameterIndicator);
  598. }
  599. else
  600. {
  601. str = ":\"" + commandLineArg.Substring(index + 1);
  602. }
  603. }
  604. Microsoft.Build.Shared.ErrorUtilities.VerifyThrow(str != null, "We must be able to extract the switch parameters.");
  605. return str;
  606. }
  607. private static CommandLineSwitches GatherAllSwitches(string commandLine)
  608. {
  609. ArrayList commandLineArgs = QuotingUtilities.SplitUnquoted(commandLine, new char[0]);
  610. commandLineArgs.RemoveAt(0);
  611. CommandLineSwitches commandLineSwitches = new CommandLineSwitches();
  612. GatherCommandLineSwitches(commandLineArgs, commandLineSwitches);
  613. return GatherAutoResponseFileSwitches(commandLineSwitches);
  614. }
  615. private static CommandLineSwitches GatherAutoResponseFileSwitches(CommandLineSwitches commandLineSwitches)
  616. {
  617. CommandLineSwitches switches = commandLineSwitches;
  618. if (!commandLineSwitches[CommandLineSwitches.ParameterlessSwitch.NoAutoResponse])
  619. {
  620. string path = Path.Combine(exePath, "MSBuild.rsp");
  621. if (!File.Exists(path))
  622. {
  623. return switches;
  624. }
  625. switches = new CommandLineSwitches();
  626. GatherResponseFileSwitch("@" + path, switches);
  627. if (switches[CommandLineSwitches.ParameterlessSwitch.NoAutoResponse])
  628. {
  629. switches.SetSwitchError("CannotAutoDisableAutoResponseFile", switches.GetParameterlessSwitchCommandLineArg(CommandLineSwitches.ParameterlessSwitch.NoAutoResponse));
  630. }
  631. if (switches.HaveAnySwitchesBeenSet())
  632. {
  633. usingSwitchesFromAutoResponseFile = true;
  634. }
  635. switches.Append(commandLineSwitches);
  636. }
  637. return switches;
  638. }
  639. internal static void GatherCommandLineSwitches(ArrayList commandLineArgs, CommandLineSwitches commandLineSwitches)
  640. {
  641. foreach (string str in commandLineArgs)
  642. {
  643. int num;
  644. string unquotedCommandLineArg = QuotingUtilities.Unquote(str, out num);
  645. if (unquotedCommandLineArg.Length > 0)
  646. {
  647. string str3;
  648. string str4;
  649. CommandLineSwitches.ParameterlessSwitch switch2;
  650. string str5;
  651. if (unquotedCommandLineArg.StartsWith("@", StringComparison.Ordinal))
  652. {
  653. GatherResponseFileSwitch(unquotedCommandLineArg, commandLineSwitches);
  654. continue;
  655. }
  656. if (!unquotedCommandLineArg.StartsWith("-", StringComparison.Ordinal) && !unquotedCommandLineArg.StartsWith("/", StringComparison.Ordinal))
  657. {
  658. str3 = null;
  659. str4 = ":" + str;
  660. }
  661. else
  662. {
  663. int index = unquotedCommandLineArg.IndexOf(':');
  664. if (index == -1)
  665. {
  666. str3 = unquotedCommandLineArg.Substring(1);
  667. str4 = string.Empty;
  668. }
  669. else
  670. {
  671. str3 = unquotedCommandLineArg.Substring(1, index - 1);
  672. str4 = ExtractSwitchParameters(str, unquotedCommandLineArg, num, str3, index);
  673. }
  674. }
  675. if (string.IsNullOrEmpty(str4) && (string.Equals(str3, "m", StringComparison.OrdinalIgnoreCase) || string.Equals(str3, "maxcpucount", StringComparison.OrdinalIgnoreCase)))
  676. {
  677. int processorCount = Environment.ProcessorCount;
  678. str4 = ":" + processorCount;
  679. }
  680. if (CommandLineSwitches.IsParameterlessSwitch(str3, out switch2, out str5))
  681. {
  682. GatherParameterlessCommandLineSwitch(commandLineSwitches, switch2, str4, str5, unquotedCommandLineArg);
  683. }
  684. else
  685. {
  686. CommandLineSwitches.ParameterizedSwitch switch3;
  687. bool flag;
  688. string str6;
  689. bool flag2;
  690. if (CommandLineSwitches.IsParameterizedSwitch(str3, out switch3, out str5, out flag, out str6, out flag2))
  691. {
  692. GatherParameterizedCommandLineSwitch(commandLineSwitches, switch3, str4, str5, flag, str6, flag2, unquotedCommandLineArg);
  693. continue;
  694. }
  695. commandLineSwitches.SetUnknownSwitchError(unquotedCommandLineArg);
  696. }
  697. }
  698. }
  699. }
  700. private static void GatherParameterizedCommandLineSwitch(CommandLineSwitches commandLineSwitches, CommandLineSwitches.ParameterizedSwitch parameterizedSwitch, string switchParameters, string duplicateSwitchErrorMessage, bool multipleParametersAllowed, string missingParametersErrorMessage, bool unquoteParameters, string unquotedCommandLineArg)
  701. {
  702. if ((switchParameters.Length > 1) || (missingParametersErrorMessage == null))
  703. {
  704. if (commandLineSwitches.IsParameterizedSwitchSet(parameterizedSwitch) && (duplicateSwitchErrorMessage != null))
  705. {
  706. commandLineSwitches.SetSwitchError(duplicateSwitchErrorMessage, unquotedCommandLineArg);
  707. }
  708. else
  709. {
  710. if (switchParameters.Length > 0)
  711. {
  712. switchParameters = switchParameters.Substring(1);
  713. }
  714. if (!commandLineSwitches.SetParameterizedSwitch(parameterizedSwitch, unquotedCommandLineArg, switchParameters, multipleParametersAllowed, unquoteParameters) && (missingParametersErrorMessage != null))
  715. {
  716. commandLineSwitches.SetSwitchError(missingParametersErrorMessage, unquotedCommandLineArg);
  717. }
  718. }
  719. }
  720. else
  721. {
  722. commandLineSwitches.SetSwitchError(missingParametersErrorMessage, unquotedCommandLineArg);
  723. }
  724. }
  725. private static void GatherParameterlessCommandLineSwitch(CommandLineSwitches commandLineSwitches, CommandLineSwitches.ParameterlessSwitch parameterlessSwitch, string switchParameters, string duplicateSwitchErrorMessage, string unquotedCommandLineArg)
  726. {
  727. if (switchParameters.Length == 0)
  728. {
  729. if (!commandLineSwitches.IsParameterlessSwitchSet(parameterlessSwitch) || (duplicateSwitchErrorMessage == null))
  730. {
  731. commandLineSwitches.SetParameterlessSwitch(parameterlessSwitch, unquotedCommandLineArg);
  732. }
  733. else
  734. {
  735. commandLineSwitches.SetSwitchError(duplicateSwitchErrorMessage, unquotedCommandLineArg);
  736. }
  737. }
  738. else
  739. {
  740. commandLineSwitches.SetUnexpectedParametersError(unquotedCommandLineArg);
  741. }
  742. }
  743. private static void GatherResponseFileSwitch(string unquotedCommandLineArg, CommandLineSwitches commandLineSwitches)
  744. {
  745. try
  746. {
  747. string path = unquotedCommandLineArg.Substring(1);
  748. if (path.Length == 0)
  749. {
  750. commandLineSwitches.SetSwitchError("MissingResponseFileError", unquotedCommandLineArg);
  751. }
  752. else if (!File.Exists(path))
  753. {
  754. commandLineSwitches.SetParameterError("ResponseFileNotFoundError", unquotedCommandLineArg);
  755. }
  756. else
  757. {
  758. path = Path.GetFullPath(path);
  759. bool flag = false;
  760. foreach (string str2 in includedResponseFiles)
  761. {
  762. if (string.Compare(path, str2, StringComparison.OrdinalIgnoreCase) == 0)
  763. {
  764. commandLineSwitches.SetParameterError("RepeatedResponseFileError", unquotedCommandLineArg);
  765. flag = true;
  766. break;
  767. }
  768. }
  769. if (!flag)
  770. {
  771. ArrayList list;
  772. includedResponseFiles.Add(path);
  773. using (StreamReader reader = new StreamReader(path, Encoding.Default))
  774. {
  775. list = new ArrayList();
  776. while (reader.Peek() != -1)
  777. {
  778. string name = reader.ReadLine().TrimStart(new char[0]);
  779. if (!name.StartsWith("#", StringComparison.Ordinal))
  780. {
  781. list.AddRange(QuotingUtilities.SplitUnquoted(Environment.ExpandEnvironmentVariables(name), new char[0]));
  782. }
  783. }
  784. }
  785. GatherCommandLineSwitches(list, commandLineSwitches);
  786. }
  787. }
  788. }
  789. catch (NotSupportedException exception)
  790. {
  791. commandLineSwitches.SetParameterError("ReadResponseFileError", unquotedCommandLineArg, exception);
  792. }
  793. catch (SecurityException exception2)
  794. {
  795. commandLineSwitches.SetParameterError("ReadResponseFileError", unquotedCommandLineArg, exception2);
  796. }
  797. catch (UnauthorizedAccessException exception3)
  798. {
  799. commandLineSwitches.SetParameterError("ReadResponseFileError", unquotedCommandLineArg, exception3);
  800. }
  801. catch (IOException exception4)
  802. {
  803. commandLineSwitches.SetParameterError("ReadResponseFileError", unquotedCommandLineArg, exception4);
  804. }
  805. }
  806. private static string GetFriendlyCounterType(PerformanceCounterType type, string name)
  807. {
  808. if (name.IndexOf("bytes", StringComparison.OrdinalIgnoreCase) != -1)
  809. {
  810. return "bytes";
  811. }
  812. if (name.IndexOf("threads", StringComparison.OrdinalIgnoreCase) != -1)
  813. {
  814. return "threads";
  815. }
  816. switch (type)
  817. {
  818. case PerformanceCounterType.NumberOfItems64:
  819. case PerformanceCounterType.CounterDelta32:
  820. case PerformanceCounterType.CounterDelta64:
  821. case PerformanceCounterType.NumberOfItemsHEX32:
  822. case PerformanceCounterType.NumberOfItemsHEX64:
  823. case PerformanceCounterType.NumberOfItems32:
  824. case PerformanceCounterType.SampleCounter:
  825. case PerformanceCounterType.CountPerTimeInterval32:
  826. case PerformanceCounterType.CountPerTimeInterval64:
  827. case PerformanceCounterType.CounterTimer:
  828. case PerformanceCounterType.RateOfCountsPerSecond32:
  829. case PerformanceCounterType.RateOfCountsPerSecond64:
  830. case PerformanceCounterType.CounterMultiTimer:
  831. case PerformanceCounterType.CounterTimerInverse:
  832. case PerformanceCounterType.CounterMultiTimerInverse:
  833. case PerformanceCounterType.AverageCount64:
  834. return "#";
  835. case PerformanceCounterType.RawFraction:
  836. case PerformanceCounterType.CounterMultiTimer100Ns:
  837. case PerformanceCounterType.SampleFraction:
  838. case PerformanceCounterType.CounterMultiTimer100NsInverse:
  839. return "%";
  840. case PerformanceCounterType.Timer100NsInverse:
  841. case PerformanceCounterType.Timer100Ns:
  842. return "100ns";
  843. case PerformanceCounterType.AverageTimer32:
  844. case PerformanceCounterType.ElapsedTime:
  845. return "s";
  846. }
  847. return "?";
  848. }
  849. private static void HandleConfigurationException(Exception ex)
  850. {
  851. StringBuilder builder = new StringBuilder();
  852. Exception innerException = ex;
  853. do
  854. {
  855. string str = innerException.Message.TrimEnd(new char[0]);
  856. builder.Append(str);
  857. if (str[str.Length - 1] != '.')
  858. {
  859. builder.Append(".");
  860. }
  861. builder.Append(" ");
  862. innerException = innerException.InnerException;
  863. }
  864. while (innerException != null);
  865. Console.WriteLine(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("InvalidConfigurationFile", new object[] { builder.ToString() }));
  866. initialized = false;
  867. }
  868. internal static void Initialize()
  869. {
  870. }
  871. [MTAThread]
  872. public static int Main()
  873. {
  874. if (Environment.GetEnvironmentVariable("MSBUILDDUMPPROCESSCOUNTERS") == "1")
  875. {
  876. DumpCounters(true);
  877. }
  878. int num = (initialized && (Execute(Environment.CommandLine) == ExitType.Success)) ? 0 : 1;
  879. if (Environment.GetEnvironmentVariable("MSBUILDDUMPPROCESSCOUNTERS") == "1")
  880. {
  881. DumpCounters(false);
  882. }
  883. return num;
  884. }
  885. [MethodImpl(MethodImplOptions.NoInlining)]
  886. private static ExitType OldOMBuildProject(ExitType exitType, string projectFile, string[] targets, string toolsVersion, Dictionary<string, string> globalProperties, ILogger[] loggers, LoggerVerbosity verbosity, bool needToValidateProject, string schemaFile, int cpuCount)
  887. {
  888. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("Using35Engine"));
  889. BuildPropertyGroup propertyBag = new BuildPropertyGroup();
  890. foreach (KeyValuePair<string, string> pair in globalProperties)
  891. {
  892. propertyBag.SetProperty(pair.Key, pair.Value);
  893. }
  894. if (!BuildProjectWithOldOM(projectFile, targets, toolsVersion, propertyBag, loggers, verbosity, null, needToValidateProject, schemaFile, cpuCount))
  895. {
  896. exitType = ExitType.BuildError;
  897. }
  898. return exitType;
  899. }
  900. private static Microsoft.Build.Logging.LoggerDescription ParseLoggingParameter(string parameter, string unquotedParameter, LoggerVerbosity verbosity)
  901. {
  902. string str;
  903. string loggerSwitchParameters = null;
  904. int num;
  905. string str5;
  906. ArrayList list = QuotingUtilities.SplitUnquoted(parameter, 2, true, false, out num, new char[] { ';' });
  907. Microsoft.Build.Shared.ErrorUtilities.VerifyThrow((list.Count >= 1) && (list.Count <= 2), "SplitUnquoted() must return at least one string, and no more than two.");
  908. CommandLineSwitchException.VerifyThrow(((string) list[0]).Length > 0, "InvalidLoggerError", unquotedParameter);
  909. if (list.Count == 2)
  910. {
  911. loggerSwitchParameters = QuotingUtilities.Unquote((string) list[1]);
  912. }
  913. ArrayList list2 = QuotingUtilities.SplitUnquoted((string) list[0], 2, true, false, out num, new char[] { ',' });
  914. Microsoft.Build.Shared.ErrorUtilities.VerifyThrow((list2.Count >= 1) && (list2.Count <= 2), "SplitUnquoted() must return at least one string, and no more than two.");
  915. if (list2.Count == 2)
  916. {
  917. str = QuotingUtilities.Unquote((string) list2[0]);
  918. str5 = QuotingUtilities.Unquote((string) list2[1]);
  919. }
  920. else
  921. {
  922. str = string.Empty;
  923. str5 = QuotingUtilities.Unquote((string) list2[0]);
  924. }
  925. CommandLineSwitchException.VerifyThrow(str5.Length > 0, "InvalidLoggerError", unquotedParameter);
  926. string loggerAssemblyName = null;
  927. string loggerAssemblyFile = null;
  928. if (string.Compare(str5, "Microsoft.Build.Engine", StringComparison.OrdinalIgnoreCase) == 0)
  929. {
  930. str5 = "Microsoft.Build.Engine,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a";
  931. }
  932. if (File.Exists(str5))
  933. {
  934. loggerAssemblyFile = str5;
  935. }
  936. else
  937. {
  938. loggerAssemblyName = str5;
  939. }
  940. return new Microsoft.Build.Logging.LoggerDescription(str, loggerAssemblyName, loggerAssemblyFile, loggerSwitchParameters, verbosity);
  941. }
  942. private static bool ProcessCommandLineSwitches(CommandLineSwitches commandLineSwitches, ref string projectFile, ref string[] targets, ref string toolsVersion, ref Dictionary<string, string> globalProperties, ref ILogger[] loggers, ref LoggerVerbosity verbosity, ref List<DistributedLoggerRecord> distributedLoggerRecords, ref bool needToValidateProject, ref string schemaFile, ref int cpuCount, ref bool enableNodeReuse, ref TextWriter preprocessWriter, ref bool debugger, ref bool detailedSummary)
  943. {
  944. bool flag = false;
  945. if (!commandLineSwitches[CommandLineSwitches.ParameterlessSwitch.NoLogo] && !commandLineSwitches.IsParameterizedSwitchSet(CommandLineSwitches.ParameterizedSwitch.Preprocess))
  946. {
  947. DisplayCopyrightMessage();
  948. }
  949. if (commandLineSwitches[CommandLineSwitches.ParameterlessSwitch.Help])
  950. {
  951. ShowHelpMessage();
  952. }
  953. else if (commandLineSwitches.IsParameterizedSwitchSet(CommandLineSwitches.ParameterizedSwitch.NodeMode))
  954. {
  955. StartLocalNode(commandLineSwitches);
  956. }
  957. else
  958. {
  959. commandLineSwitches.ThrowErrors();
  960. if (commandLineSwitches[CommandLineSwitches.ParameterlessSwitch.Version])
  961. {
  962. ShowVersion();
  963. }
  964. else
  965. {
  966. projectFile = ProcessProjectSwitch(commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.Project], commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.IgnoreProjectExtensions], new Microsoft.Build.Shared.DirectoryGetFiles(Directory.GetFiles));
  967. targets = ProcessTargetSwitch(commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.Target]);
  968. toolsVersion = ProcessToolsVersionSwitch(commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.ToolsVersion]);
  969. globalProperties = ProcessPropertySwitch(commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.Property]);
  970. cpuCount = ProcessMaxCPUCountSwitch(commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.MaxCPUCount]);
  971. enableNodeReuse = ProcessNodeReuseSwitch(commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.NodeReuse]);
  972. preprocessWriter = null;
  973. if (commandLineSwitches.IsParameterizedSwitchSet(CommandLineSwitches.ParameterizedSwitch.Preprocess))
  974. {
  975. preprocessWriter = ProcessPreprocessSwitch(commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.Preprocess]);
  976. }
  977. debugger = commandLineSwitches.IsParameterlessSwitchSet(CommandLineSwitches.ParameterlessSwitch.Debugger);
  978. detailedSummary = commandLineSwitches.IsParameterlessSwitchSet(CommandLineSwitches.ParameterlessSwitch.DetailedSummary);
  979. string[][] fileLoggerParameters = commandLineSwitches.GetFileLoggerParameters();
  980. loggers = ProcessLoggingSwitches(commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.Logger], commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.DistributedLogger], commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.Verbosity], commandLineSwitches[CommandLineSwitches.ParameterlessSwitch.NoConsoleLogger], commandLineSwitches[CommandLineSwitches.ParameterlessSwitch.DistributedFileLogger], commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.FileLoggerParameters], commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.ConsoleLoggerParameters], fileLoggerParameters, out distributedLoggerRecords, out verbosity, ref detailedSummary, cpuCount);
  981. if (usingSwitchesFromAutoResponseFile && (LoggerVerbosity.Diagnostic == verbosity))
  982. {
  983. Console.WriteLine(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("PickedUpSwitchesFromAutoResponse", new object[] { "MSBuild.rsp" }));
  984. }
  985. needToValidateProject = commandLineSwitches.IsParameterizedSwitchSet(CommandLineSwitches.ParameterizedSwitch.Validate);
  986. schemaFile = ProcessValidateSwitch(commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.Validate]);
  987. flag = true;
  988. }
  989. }
  990. Microsoft.Build.Shared.ErrorUtilities.VerifyThrow(!flag || (projectFile != null), "We should have a project file if we're going to build.");
  991. return flag;
  992. }
  993. internal static void ProcessConsoleLoggerSwitch(bool noConsoleLogger, string[] consoleLoggerParameters, List<DistributedLoggerRecord> distributedLoggerRecords, LoggerVerbosity verbosity, int cpuCount, ArrayList loggers)
  994. {
  995. if (!noConsoleLogger)
  996. {
  997. Microsoft.Build.Logging.ConsoleLogger logger = new Microsoft.Build.Logging.ConsoleLogger(verbosity);
  998. string anyPrefixingParameter = "SHOWPROJECTFILE=TRUE;";
  999. if ((consoleLoggerParameters != null) && (consoleLoggerParameters.Length > 0))
  1000. {
  1001. anyPrefixingParameter = AggregateParameters(anyPrefixingParameter, consoleLoggerParameters);
  1002. }
  1003. if (cpuCount == 1)
  1004. {
  1005. logger.Parameters = "ENABLEMPLOGGING;" + anyPrefixingParameter;
  1006. loggers.Add(logger);
  1007. }
  1008. else
  1009. {
  1010. logger.Parameters = anyPrefixingParameter;
  1011. DistributedLoggerRecord item = CreateForwardingLoggerRecord(logger, anyPrefixingParameter, verbosity);
  1012. distributedLoggerRecords.Add(item);
  1013. }
  1014. }
  1015. }
  1016. internal static void ProcessDistributedFileLogger(bool distributedFileLogger, string[] fileLoggerParameters, List<DistributedLoggerRecord> distributedLoggerRecords, ArrayList loggers, int cpuCount)
  1017. {
  1018. if (distributedFileLogger)
  1019. {
  1020. string parameters = string.Empty;
  1021. if ((fileLoggerParameters != null) && (fileLoggerParameters.Length > 0))
  1022. {
  1023. parameters = AggregateParameters(null, fileLoggerParameters);
  1024. }
  1025. string parameter = ExtractAnyLoggerParameter(parameters, new string[] { "logfile" });
  1026. string str3 = ExtractAnyParameterValue(parameter);
  1027. try
  1028. {
  1029. if (!string.IsNullOrEmpty(str3) && !Path.IsPathRooted(str3))
  1030. {
  1031. parameters = parameters.Replace(parameter, "logFile=" + Path.Combine(Environment.CurrentDirectory, str3));
  1032. }
  1033. }
  1034. catch (Exception exception)
  1035. {
  1036. if (Microsoft.Build.Shared.ExceptionHandling.NotExpectedException(exception))
  1037. {
  1038. throw;
  1039. }
  1040. throw new LoggerException(exception.Message, exception);
  1041. }
  1042. if (string.IsNullOrEmpty(str3))
  1043. {
  1044. if (!string.IsNullOrEmpty(parameters) && !parameters.EndsWith(";", StringComparison.OrdinalIgnoreCase))
  1045. {
  1046. parameters = parameters + ";";
  1047. }
  1048. parameters = parameters + "logFile=" + Path.Combine(Environment.CurrentDirectory, "msbuild.log");
  1049. }
  1050. Assembly assembly = Assembly.GetAssembly(typeof(ProjectCollection));
  1051. string loggerClassName = "Microsoft.Build.Logging.DistributedFileLogger";
  1052. string fullName = assembly.GetName().FullName;
  1053. Microsoft.Build.Logging.LoggerDescription forwardingLoggerDescription = new Microsoft.Build.Logging.LoggerDescription(loggerClassName, fullName, null, parameters, LoggerVerbosity.Detailed);
  1054. DistributedLoggerRecord item = new DistributedLoggerRecord(null, forwardingLoggerDescription);
  1055. distributedLoggerRecords.Add(item);
  1056. }
  1057. }
  1058. private static List<DistributedLoggerRecord> ProcessDistributedLoggerSwitch(string[] parameters, LoggerVerbosity verbosity)
  1059. {
  1060. List<DistributedLoggerRecord> list = new List<DistributedLoggerRecord>();
  1061. foreach (string str in parameters)
  1062. {
  1063. int num;
  1064. ArrayList list2 = QuotingUtilities.SplitUnquoted(str, 2, true, false, out num, new char[] { '*' });
  1065. Microsoft.Build.Shared.ErrorUtilities.VerifyThrow((list2.Count >= 1) && (list2.Count <= 2), "SplitUnquoted() must return at least one string, and no more than two.");
  1066. string unquotedParameter = QuotingUtilities.Unquote((string) list2[0]);
  1067. Microsoft.Build.Logging.LoggerDescription loggerDescription = ParseLoggingParameter((string) list2[0], unquotedParameter, verbosity);
  1068. ILogger centralLogger = CreateAndConfigureLogger(loggerDescription, verbosity, unquotedParameter);
  1069. Microsoft.Build.Logging.LoggerDescription forwardingLoggerDescription = loggerDescription;
  1070. if (list2.Count > 1)
  1071. {
  1072. unquotedParameter = QuotingUtilities.Unquote((string) list2[1]);
  1073. forwardingLoggerDescription = ParseLoggingParameter((string) list2[1], unquotedParameter, verbosity);
  1074. }
  1075. DistributedLoggerRecord item = new DistributedLoggerRecord(centralLogger, forwardingLoggerDescription);
  1076. list.Add(item);
  1077. }
  1078. return list;
  1079. }
  1080. private static void ProcessFileLoggers(string[][] groupedFileLoggerParameters, List<DistributedLoggerRecord> distributedLoggerRecords, LoggerVerbosity verbosity, int cpuCount, ArrayList loggers)
  1081. {
  1082. for (int i = 0; i < groupedFileLoggerParameters.Length; i++)
  1083. {
  1084. if (groupedFileLoggerParameters[i] != null)
  1085. {
  1086. string anyPrefixingParameter = "SHOWPROJECTFILE=TRUE;";
  1087. if (i == 0)
  1088. {
  1089. anyPrefixingParameter = anyPrefixingParameter + "logfile=msbuild.log;";
  1090. }
  1091. else
  1092. {
  1093. object obj2 = anyPrefixingParameter;
  1094. anyPrefixingParameter = string.Concat(new object[] { obj2, "logfile=msbuild", i, ".log;" });
  1095. }
  1096. if (groupedFileLoggerParameters[i].Length > 0)
  1097. {
  1098. anyPrefixingParameter = AggregateParameters(anyPrefixingParameter, groupedFileLoggerParameters[i]);
  1099. }
  1100. Microsoft.Build.Logging.FileLogger logger = new Microsoft.Build.Logging.FileLogger();
  1101. LoggerVerbosity detailed = LoggerVerbosity.Detailed;
  1102. logger.Verbosity = detailed;
  1103. if (cpuCount == 1)
  1104. {
  1105. logger.Parameters = "ENABLEMPLOGGING;" + anyPrefixingParameter;
  1106. loggers.Add(logger);
  1107. }
  1108. else
  1109. {
  1110. logger.Parameters = anyPrefixingParameter;
  1111. DistributedLoggerRecord item = CreateForwardingLoggerRecord(logger, anyPrefixingParameter, detailed);
  1112. distributedLoggerRecords.Add(item);
  1113. }
  1114. }
  1115. }
  1116. }
  1117. private static ArrayList ProcessLoggerSwitch(string[] parameters, LoggerVerbosity verbosity)
  1118. {
  1119. ArrayList list = new ArrayList();
  1120. foreach (string str in parameters)
  1121. {
  1122. string unquotedParameter = QuotingUtilities.Unquote(str);
  1123. Microsoft.Build.Logging.LoggerDescription loggerDescription = ParseLoggingParameter(str, unquotedParameter, verbosity);
  1124. list.Add(CreateAndConfigureLogger(loggerDescription, verbosity, unquotedParameter));
  1125. }
  1126. return list;
  1127. }
  1128. private static ILogger[] ProcessLoggingSwitches(string[] loggerSwitchParameters, string[] distributedLoggerSwitchParameters, string[] verbositySwitchParameters, bool noConsoleLogger, bool distributedFileLogger, string[] fileLoggerParameters, string[] consoleLoggerParameters, string[][] groupedFileLoggerParameters, out List<DistributedLoggerRecord> distributedLoggerRecords, out LoggerVerbosity verbosity, ref bool detailedSummary, int cpuCount)
  1129. {
  1130. verbosity = LoggerVerbosity.Normal;
  1131. if (verbositySwitchParameters.Length > 0)
  1132. {
  1133. verbosity = ProcessVerbositySwitch(verbositySwitchParameters[verbositySwitchParameters.Length - 1]);
  1134. }
  1135. ArrayList loggers = ProcessLoggerSwitch(loggerSwitchParameters, verbosity);
  1136. distributedLoggerRecords = ProcessDistributedLoggerSwitch(distributedLoggerSwitchParameters, verbosity);
  1137. ProcessConsoleLoggerSwitch(noConsoleLogger, consoleLoggerParameters, distributedLoggerRecords, verbosity, cpuCount, loggers);
  1138. ProcessDistributedFileLogger(distributedFileLogger, fileLoggerParameters, distributedLoggerRecords, loggers, cpuCount);
  1139. ProcessFileLoggers(groupedFileLoggerParameters, distributedLoggerRecords, verbosity, cpuCount, loggers);
  1140. if (verbosity == LoggerVerbosity.Diagnostic)
  1141. {
  1142. detailedSummary = true;
  1143. }
  1144. return (ILogger[]) loggers.ToArray(typeof(ILogger));
  1145. }
  1146. internal static int ProcessMaxCPUCountSwitch(string[] parameters)
  1147. {
  1148. int num = 1;
  1149. if (parameters.Length > 0)
  1150. {
  1151. try
  1152. {
  1153. num = int.Parse(parameters[parameters.Length - 1], CultureInfo.InvariantCulture);
  1154. }
  1155. catch (FormatException exception)
  1156. {
  1157. CommandLineSwitchException.Throw("InvalidMaxCPUCountValue", parameters[parameters.Length - 1], new string[] { exception.Message });
  1158. }
  1159. catch (OverflowException exception2)
  1160. {
  1161. CommandLineSwitchException.Throw("InvalidMaxCPUCountValue", parameters[parameters.Length - 1], new string[] { exception2.Message });
  1162. }
  1163. CommandLineSwitchException.VerifyThrow((num > 0) && (num < 0x40), "InvalidMaxCPUCountValueOutsideRange", parameters[parameters.Length - 1]);
  1164. }
  1165. return num;
  1166. }
  1167. internal static bool ProcessNodeReuseSwitch(string[] parameters)
  1168. {
  1169. bool flag = true;
  1170. if (parameters.Length > 0)
  1171. {
  1172. try
  1173. {
  1174. flag = bool.Parse(parameters[parameters.Length - 1]);
  1175. }
  1176. catch (FormatException exception)
  1177. {
  1178. CommandLineSwitchException.Throw("InvalidNodeReuseValue", parameters[parameters.Length - 1], new string[] { exception.Message });
  1179. }
  1180. catch (ArgumentNullException exception2)
  1181. {
  1182. CommandLineSwitchException.Throw("InvalidNodeReuseValue", parameters[parameters.Length - 1], new string[] { exception2.Message });
  1183. }
  1184. }
  1185. return flag;
  1186. }
  1187. internal static TextWriter ProcessPreprocessSwitch(string[] parameters)
  1188. {
  1189. TextWriter @out = Console.Out;
  1190. if (parameters.Length > 0)
  1191. {
  1192. try
  1193. {
  1194. @out = new StreamWriter(parameters[parameters.Length - 1]);
  1195. }
  1196. catch (Exception exception)
  1197. {
  1198. if (Microsoft.Build.Shared.ExceptionHandling.NotExpectedException(exception))
  1199. {
  1200. throw;
  1201. }
  1202. CommandLineSwitchException.Throw("InvalidPreprocessPath", parameters[parameters.Length - 1], new string[] { exception.Message });
  1203. }
  1204. }
  1205. return @out;
  1206. }
  1207. internal static string ProcessProjectSwitch(string[] parameters, string[] projectsExtensionsToIgnore, Microsoft.Build.Shared.DirectoryGetFiles getFiles)
  1208. {
  1209. Microsoft.Build.Shared.ErrorUtilities.VerifyThrow(parameters.Length <= 1, "It should not be possible to specify more than 1 project at a time.");
  1210. if (parameters.Length == 0)
  1211. {
  1212. string[] potentialProjectOrSolutionFiles = getFiles(".", "*.*proj");
  1213. string[] strArray2 = getFiles(".", "*.sln");
  1214. Dictionary<string, object> extensionsToIgnoreDictionary = ValidateExtensions(projectsExtensionsToIgnore);
  1215. if (extensionsToIgnoreDictionary.Count > 0)
  1216. {
  1217. if ((potentialProjectOrSolutionFiles != null) && (potentialProjectOrSolutionFiles.Length > 0))
  1218. {
  1219. potentialProjectOrSolutionFiles = RemoveFilesWithExtensionsToIgnore(potentialProjectOrSolutionFiles, extensionsToIgnoreDictionary);
  1220. }
  1221. if ((strArray2 != null) && (strArray2.Length > 0))
  1222. {
  1223. strArray2 = RemoveFilesWithExtensionsToIgnore(strArray2, extensionsToIgnoreDictionary);
  1224. }
  1225. }
  1226. if ((potentialProjectOrSolutionFiles.Length == 1) && (strArray2.Length == 1))
  1227. {
  1228. string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(strArray2[0]);
  1229. string strB = Path.GetFileNameWithoutExtension(potentialProjectOrSolutionFiles[0]);
  1230. InitializationException.VerifyThrow(string.Compare(fileNameWithoutExtension, strB, StringComparison.OrdinalIgnoreCase) == 0, "AmbiguousProjectError");
  1231. }
  1232. else if (strArray2.Length > 1)
  1233. {
  1234. InitializationException.VerifyThrow(false, "AmbiguousProjectError");
  1235. }
  1236. else if (potentialProjectOrSolutionFiles.Length > 1)
  1237. {
  1238. bool flag = true;
  1239. if (potentialProjectOrSolutionFiles.Length == 2)
  1240. {
  1241. string extension = Path.GetExtension(potentialProjectOrSolutionFiles[0]);
  1242. string str5 = Path.GetExtension(potentialProjectOrSolutionFiles[1]);
  1243. if (string.Compare(extension, str5, StringComparison.OrdinalIgnoreCase) != 0)
  1244. {
  1245. if (string.Compare(extension, ".proj", StringComparison.OrdinalIgnoreCase) == 0)
  1246. {
  1247. potentialProjectOrSolutionFiles = new string[] { potentialProjectOrSolutionFiles[0] };
  1248. flag = false;
  1249. }
  1250. else if (string.Compare(str5, ".proj", StringComparison.OrdinalIgnoreCase) == 0)
  1251. {
  1252. potentialProjectOrSolutionFiles = new string[] { potentialProjectOrSolutionFiles[1] };
  1253. flag = false;
  1254. }
  1255. }
  1256. }
  1257. InitializationException.VerifyThrow(!flag, "AmbiguousProjectError");
  1258. }
  1259. else if ((potentialProjectOrSolutionFiles.Length == 0) && (strArray2.Length == 0))
  1260. {
  1261. InitializationException.VerifyThrow(false, "MissingProjectError");
  1262. }
  1263. return ((strArray2.Length == 1) ? strArray2[0] : potentialProjectOrSolutionFiles[0]);
  1264. }
  1265. InitializationException.VerifyThrow(File.Exists(parameters[0]), "ProjectNotFoundError", parameters[0]);
  1266. return parameters[0];
  1267. }
  1268. internal static Dictionary<string, string> ProcessPropertySwitch(string[] parameters)
  1269. {
  1270. Dictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  1271. foreach (string str in parameters)
  1272. {
  1273. string[] strArray = str.Split(propertyValueSeparator, 2);
  1274. CommandLineSwitchException.VerifyThrow((strArray[0].Length > 0) && (strArray.Length == 2), "InvalidPropertyError", str);
  1275. dictionary[strArray[0]] = strArray[1];
  1276. }
  1277. return dictionary;
  1278. }
  1279. private static string[] ProcessTargetSwitch(string[] parameters)
  1280. {
  1281. return parameters;
  1282. }
  1283. private static string ProcessToolsVersionSwitch(string[] parameters)
  1284. {
  1285. if (parameters.Length > 0)
  1286. {
  1287. return parameters[parameters.Length - 1];
  1288. }
  1289. return null;
  1290. }
  1291. private static string ProcessValidateSwitch(string[] parameters)
  1292. {
  1293. string str = null;
  1294. foreach (string str2 in parameters)
  1295. {
  1296. InitializationException.VerifyThrow(str == null, "MultipleSchemasError", str2);
  1297. InitializationException.VerifyThrow(File.Exists(str2), "SchemaNotFoundError", str2);
  1298. str = Path.Combine(Directory.GetCurrentDirectory(), str2);
  1299. }
  1300. return str;
  1301. }
  1302. internal static LoggerVerbosity ProcessVerbositySwitch(string value)
  1303. {
  1304. LoggerVerbosity normal = LoggerVerbosity.Normal;
  1305. if (string.Equals(value, "q", StringComparison.OrdinalIgnoreCase) || string.Equals(value, "quiet", StringComparison.OrdinalIgnoreCase))
  1306. {
  1307. return LoggerVerbosity.Quiet;
  1308. }
  1309. if (string.Equals(value, "m", StringComparison.OrdinalIgnoreCase) || string.Equals(value, "minimal", StringComparison.OrdinalIgnoreCase))
  1310. {
  1311. return LoggerVerbosity.Minimal;
  1312. }
  1313. if (string.Equals(value, "n", StringComparison.OrdinalIgnoreCase) || string.Equals(value, "normal", StringComparison.OrdinalIgnoreCase))
  1314. {
  1315. return LoggerVerbosity.Normal;
  1316. }
  1317. if (string.Equals(value, "d", StringComparison.OrdinalIgnoreCase) || string.Equals(value, "detailed", StringComparison.OrdinalIgnoreCase))
  1318. {
  1319. return LoggerVerbosity.Detailed;
  1320. }
  1321. if (string.Equals(value, "diag", StringComparison.OrdinalIgnoreCase) || string.Equals(value, "diagnostic", StringComparison.OrdinalIgnoreCase))
  1322. {
  1323. return LoggerVerbosity.Diagnostic;
  1324. }
  1325. CommandLineSwitchException.Throw("InvalidVerbosityError", value);
  1326. return normal;
  1327. }
  1328. private static string[] RemoveFilesWithExtensionsToIgnore(string[] potentialProjectOrSolutionFiles, Dictionary<string, object> extensionsToIgnoreDictionary)
  1329. {
  1330. Microsoft.Build.Shared.ErrorUtilities.VerifyThrow((potentialProjectOrSolutionFiles != null) && (potentialProjectOrSolutionFiles.Length > 0), "There should be some potential project or solution files");
  1331. Microsoft.Build.Shared.ErrorUtilities.VerifyThrow((extensionsToIgnoreDictionary != null) && (extensionsToIgnoreDictionary.Count > 0), "There should be some extensions to Ignore");
  1332. List<string> list = new List<string>();
  1333. foreach (string str in potentialProjectOrSolutionFiles)
  1334. {
  1335. string extension = Path.GetExtension(str);
  1336. if (!extensionsToIgnoreDictionary.ContainsKey(extension))
  1337. {
  1338. list.Add(str);
  1339. }
  1340. }
  1341. return list.ToArray();
  1342. }
  1343. private static void ResetBuildState()
  1344. {
  1345. includedResponseFiles = new ArrayList();
  1346. usingSwitchesFromAutoResponseFile = false;
  1347. }
  1348. internal static void SetConsoleUI()
  1349. {
  1350. Thread currentThread = Thread.CurrentThread;
  1351. currentThread.CurrentUICulture = CultureInfo.CurrentUICulture.GetConsoleFallbackUICulture();
  1352. int codePage = Console.OutputEncoding.CodePage;
  1353. if (((codePage != 0xfde9) && (codePage != currentThread.CurrentUICulture.TextInfo.OEMCodePage)) && (codePage != currentThread.CurrentUICulture.TextInfo.ANSICodePage))
  1354. {
  1355. currentThread.CurrentUICulture = new CultureInfo("en-US");
  1356. }
  1357. }
  1358. private static void ShowHelpMessage()
  1359. {
  1360. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_1_Syntax"));
  1361. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_2_Description"));
  1362. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_3_SwitchesHeader"));
  1363. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_9_TargetSwitch"));
  1364. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_10_PropertySwitch"));
  1365. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_17_MaximumCPUSwitch"));
  1366. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_23_ToolsVersionSwitch"));
  1367. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_12_VerbositySwitch"));
  1368. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_13_ConsoleLoggerParametersSwitch"));
  1369. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_14_NoConsoleLoggerSwitch"));
  1370. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_20_FileLoggerSwitch"));
  1371. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_22_FileLoggerParametersSwitch"));
  1372. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_18_DistributedLoggerSwitch"));
  1373. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_21_DistributedFileLoggerSwitch"));
  1374. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_11_LoggerSwitch"));
  1375. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_15_ValidateSwitch"));
  1376. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_19_IgnoreProjectExtensionsSwitch"));
  1377. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_24_NodeReuse"));
  1378. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_25_PreprocessSwitch"));
  1379. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_26_DetailedSummarySwitch"));
  1380. if (CommandLineSwitches.IsParameterlessSwitch("debug"))
  1381. {
  1382. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_27_DebuggerSwitch"));
  1383. }
  1384. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_7_ResponseFile"));
  1385. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_8_NoAutoResponseSwitch"));
  1386. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_5_NoLogoSwitch"));
  1387. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_6_VersionSwitch"));
  1388. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_4_HelpSwitch"));
  1389. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpMessage_16_Examples"));
  1390. }
  1391. private static void ShowHelpPrompt()
  1392. {
  1393. Console.WriteLine(Microsoft.Build.Shared.AssemblyResources.GetString("HelpPrompt"));
  1394. }
  1395. private static void ShowVersion()
  1396. {
  1397. Console.Write(ProjectCollection.Version.ToString());
  1398. }
  1399. private static void StartLocalNode(CommandLineSwitches commandLineSwitches)
  1400. {
  1401. string[] strArray = commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.NodeMode];
  1402. int nodeNumber = 0;
  1403. if (strArray.Length > 0)
  1404. {
  1405. try
  1406. {
  1407. nodeNumber = int.Parse(strArray[0], CultureInfo.InvariantCulture);
  1408. }
  1409. catch (FormatException exception)
  1410. {
  1411. CommandLineSwitchException.Throw("InvalidNodeNumberValue", strArray[0], new string[] { exception.Message });
  1412. }
  1413. catch (OverflowException exception2)
  1414. {
  1415. CommandLineSwitchException.Throw("InvalidNodeNumberValue", strArray[0], new string[] { exception2.Message });
  1416. }
  1417. CommandLineSwitchException.VerifyThrow(nodeNumber >= 0, "InvalidNodeNumberValueIsNegative", strArray[0]);
  1418. }
  1419. if (!commandLineSwitches[CommandLineSwitches.ParameterlessSwitch.OldOM])
  1420. {
  1421. bool flag = true;
  1422. while (flag)
  1423. {
  1424. Exception exception3;
  1425. NodeEngineShutdownReason reason = new OutOfProcNode().Run(out exception3);
  1426. if (reason == NodeEngineShutdownReason.Error)
  1427. {
  1428. throw exception3;
  1429. }
  1430. if (reason != NodeEngineShutdownReason.BuildCompleteReuse)
  1431. {
  1432. flag = false;
  1433. }
  1434. }
  1435. }
  1436. else
  1437. {
  1438. StartLocalNodeOldOM(nodeNumber);
  1439. }
  1440. }
  1441. [MethodImpl(MethodImplOptions.NoInlining)]
  1442. private static void StartLocalNodeOldOM(int nodeNumber)
  1443. {
  1444. LocalNode.StartLocalNodeServer(nodeNumber);
  1445. }
  1446. private static void ThrowInvalidToolsVersionInitializationException(IEnumerable<Microsoft.Build.Evaluation.Toolset> toolsets, string toolsVersion)
  1447. {
  1448. string str = string.Empty;
  1449. foreach (Microsoft.Build.Evaluation.Toolset toolset in toolsets)
  1450. {
  1451. str = str + "\"" + toolset.ToolsVersion + "\", ";
  1452. }
  1453. if (str.Length > 0)
  1454. {
  1455. str = str.Substring(0, str.Length - 2);
  1456. }
  1457. string str2 = Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("UnrecognizedToolsVersion", new object[] { toolsVersion, str });
  1458. InitializationException.Throw(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("InvalidToolsVersionError", new object[] { str2 }), toolsVersion);
  1459. }
  1460. private static Dictionary<string, object> ValidateExtensions(string[] projectsExtensionsToIgnore)
  1461. {
  1462. Dictionary<string, object> dictionary = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
  1463. if ((projectsExtensionsToIgnore != null) && (projectsExtensionsToIgnore.Length > 0))
  1464. {
  1465. string extension = null;
  1466. foreach (string str2 in projectsExtensionsToIgnore)
  1467. {
  1468. try
  1469. {
  1470. extension = Path.GetExtension(str2);
  1471. }
  1472. catch (ArgumentException)
  1473. {
  1474. InitializationException.Throw("InvalidExtensionToIgnore", str2, null, false);
  1475. }
  1476. InitializationException.VerifyThrow(!string.IsNullOrEmpty(extension), "InvalidExtensionToIgnore", str2);
  1477. InitializationException.VerifyThrow(extension.Length >= 2, "InvalidExtensionToIgnore", str2);
  1478. if (string.Compare(extension, str2, StringComparison.OrdinalIgnoreCase) != 0)
  1479. {
  1480. InitializationException.Throw("InvalidExtensionToIgnore", str2, null, false);
  1481. }
  1482. if (str2.IndexOfAny(wildcards) > -1)
  1483. {
  1484. InitializationException.Throw("InvalidExtensionToIgnore", str2, null, false);
  1485. }
  1486. if (!dictionary.ContainsKey(str2))
  1487. {
  1488. dictionary.Add(str2, null);
  1489. }
  1490. }
  1491. }
  1492. return dictionary;
  1493. }
  1494. private static void VerifyThrowSupportedOS()
  1495. {
  1496. if (((Environment.OSVersion.Platform == PlatformID.Win32S) || (Environment.OSVersion.Platform == PlatformID.Win32Windows)) || ((Environment.OSVersion.Platform == PlatformID.WinCE) || ((Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version.Major <= 4))))
  1497. {
  1498. InitializationException.VerifyThrow(false, "UnsupportedOS");
  1499. }
  1500. }
  1501. public enum ExitType
  1502. {
  1503. Success,
  1504. SwitchError,
  1505. InitializationError,
  1506. BuildError,
  1507. LoggerAbort,
  1508. LoggerFailure,
  1509. Unexpected
  1510. }
  1511. }
  1512. }