PageRenderTime 79ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/Microsoft.Build/Microsoft.Build/Microsoft/Build/Evaluation/ProjectCollection.cs

#
C# | 1506 lines | 1394 code | 112 blank | 0 comment | 157 complexity | 8091f0fe87c8f30a1cf292b2d4f97a32 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

  1. namespace Microsoft.Build.Evaluation
  2. {
  3. using Microsoft.Build.BackEnd;
  4. using Microsoft.Build.BackEnd.Logging;
  5. using Microsoft.Build.Collections;
  6. using Microsoft.Build.Construction;
  7. using Microsoft.Build.Exceptions;
  8. using Microsoft.Build.Execution;
  9. using Microsoft.Build.Framework;
  10. using Microsoft.Build.Internal;
  11. using Microsoft.Build.Logging;
  12. using Microsoft.Build.Shared;
  13. using System;
  14. using System.Collections;
  15. using System.Collections.Generic;
  16. using System.Diagnostics;
  17. using System.Linq;
  18. using System.Reflection;
  19. using System.Runtime;
  20. using System.Runtime.CompilerServices;
  21. using System.Threading;
  22. using System.Xml;
  23. public class ProjectCollection : IToolsetProvider, IBuildComponent, IDisposable
  24. {
  25. private string defaultToolsVersion;
  26. private static System.Version engineVersion;
  27. private PropertyDictionary<ProjectPropertyInstance> environmentProperties;
  28. private static object globalLock = new object();
  29. private static ProjectCollection globalProjectCollection;
  30. private PropertyDictionary<ProjectPropertyInstance> globalProperties;
  31. private IBuildComponentHost host;
  32. private Microsoft.Build.Execution.HostServices hostServices;
  33. private bool isBuildEnabled;
  34. private LoadedProjectCollection loadedProjects;
  35. private ILoggingService loggingService;
  36. private bool onlyLogCriticalEvents;
  37. private ToolsetDefinitionLocations toolsetDefinitionLocations;
  38. private Dictionary<string, Toolset> toolsets;
  39. private int toolsetsVersion;
  40. static ProjectCollection()
  41. {
  42. AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(ExceptionHandling.UnhandledExceptionHandler);
  43. }
  44. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  45. public ProjectCollection() : this((IDictionary<string, string>) null)
  46. {
  47. }
  48. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  49. public ProjectCollection(IDictionary<string, string> globalProperties) : this(globalProperties, null, ToolsetDefinitionLocations.Registry | ToolsetDefinitionLocations.ConfigurationFile)
  50. {
  51. }
  52. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  53. public ProjectCollection(ToolsetDefinitionLocations toolsetLocations) : this(null, null, toolsetLocations)
  54. {
  55. }
  56. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  57. public ProjectCollection(IDictionary<string, string> globalProperties, IEnumerable<ILogger> loggers, ToolsetDefinitionLocations toolsetDefinitionLocations) : this(globalProperties, loggers, null, toolsetDefinitionLocations, 1, false)
  58. {
  59. }
  60. public ProjectCollection(IDictionary<string, string> globalProperties, IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers, ToolsetDefinitionLocations toolsetDefinitionLocations, int maxNodeCount, bool onlyLogCriticalEvents)
  61. {
  62. this.isBuildEnabled = true;
  63. this.loadedProjects = new LoadedProjectCollection();
  64. this.toolsetDefinitionLocations = toolsetDefinitionLocations;
  65. this.MaxNodeCount = maxNodeCount;
  66. this.ProjectRootElementCache = new Microsoft.Build.Evaluation.ProjectRootElementCache(false);
  67. this.OnlyLogCriticalEvents = onlyLogCriticalEvents;
  68. try
  69. {
  70. this.CreateLoggingService(maxNodeCount, onlyLogCriticalEvents);
  71. this.RegisterLoggers(loggers);
  72. this.RegisterForwardingLoggers(remoteLoggers);
  73. if (globalProperties != null)
  74. {
  75. this.globalProperties = new PropertyDictionary<ProjectPropertyInstance>(globalProperties.Count);
  76. foreach (KeyValuePair<string, string> pair in globalProperties)
  77. {
  78. try
  79. {
  80. this.globalProperties.Set(new ProjectPropertyInstance(pair.Key, pair.Value));
  81. continue;
  82. }
  83. catch (ArgumentException exception)
  84. {
  85. try
  86. {
  87. ProjectErrorUtilities.ThrowInvalidProject(new ElementLocation("MSBUILD"), "InvalidProperty", exception.Message);
  88. }
  89. catch (InvalidProjectFileException exception2)
  90. {
  91. BuildEventContext buildEventContext = new BuildEventContext(0, -1, -2, -1);
  92. this.LoggingService.LogInvalidProjectFileError(buildEventContext, exception2);
  93. throw;
  94. }
  95. continue;
  96. }
  97. }
  98. }
  99. else
  100. {
  101. this.globalProperties = new PropertyDictionary<ProjectPropertyInstance>();
  102. }
  103. this.InitializeToolsetCollection();
  104. }
  105. catch (Exception)
  106. {
  107. this.ShutDownLoggingService();
  108. throw;
  109. }
  110. }
  111. public void AddToolset(Toolset toolset)
  112. {
  113. ErrorUtilities.VerifyThrowArgumentNull(toolset, "toolset");
  114. this.toolsets[toolset.ToolsVersion] = toolset;
  115. this.toolsetsVersion++;
  116. }
  117. internal void AfterUpdateLoadedProjectGlobalProperties(Project project)
  118. {
  119. ErrorUtilities.VerifyThrowInvalidOperation(object.ReferenceEquals(project.ProjectCollection, this), "OM_IncorrectObjectAssociation", "Project", "ProjectCollection");
  120. if ((project.FullPath != null) && this.loadedProjects.RemoveProject(project))
  121. {
  122. this.loadedProjects.AddProject(project);
  123. }
  124. }
  125. public bool ContainsToolset(string toolsVersion)
  126. {
  127. return (this.GetToolset(toolsVersion) != null);
  128. }
  129. private void CreateLoggingService(int maxCPUCount, bool onlyLogCriticalEvents)
  130. {
  131. this.loggingService = Microsoft.Build.BackEnd.Logging.LoggingService.CreateLoggingService(LoggerMode.Synchronous, 0);
  132. this.loggingService.MaxCPUCount = maxCPUCount;
  133. this.loggingService.OnlyLogCriticalEvents = onlyLogCriticalEvents;
  134. }
  135. public void Dispose()
  136. {
  137. this.Dispose(true);
  138. GC.SuppressFinalize(this);
  139. }
  140. protected virtual void Dispose(bool disposing)
  141. {
  142. if (disposing)
  143. {
  144. this.ShutDownLoggingService();
  145. }
  146. }
  147. public static string Escape(string unescapedString)
  148. {
  149. return EscapingUtilities.Escape(unescapedString);
  150. }
  151. public ProjectPropertyInstance GetGlobalProperty(string name)
  152. {
  153. return this.globalProperties[name];
  154. }
  155. public ICollection<Project> GetLoadedProjects(string fullPath)
  156. {
  157. return new ReadOnlyCollection<Project>(this.loadedProjects.GetMatchingProjectsIfAny(fullPath));
  158. }
  159. public Toolset GetToolset(string toolsVersion)
  160. {
  161. Toolset toolset;
  162. ErrorUtilities.VerifyThrowArgumentLength(toolsVersion, "toolsVersion");
  163. this.toolsets.TryGetValue(toolsVersion, out toolset);
  164. return toolset;
  165. }
  166. private void InitializeToolsetCollection()
  167. {
  168. this.toolsets = new Dictionary<string, Toolset>(StringComparer.OrdinalIgnoreCase);
  169. this.defaultToolsVersion = ToolsetReader.ReadAllToolsets(this.toolsets, this.EnvironmentProperties, this.globalProperties, this.toolsetDefinitionLocations);
  170. this.toolsetsVersion++;
  171. }
  172. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  173. public Project LoadProject(string fileName)
  174. {
  175. return this.LoadProject(fileName, null);
  176. }
  177. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  178. public Project LoadProject(XmlReader xmlReader)
  179. {
  180. return this.LoadProject(xmlReader, null);
  181. }
  182. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  183. public Project LoadProject(string fileName, string toolsVersion)
  184. {
  185. return this.LoadProject(fileName, null, toolsVersion);
  186. }
  187. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  188. public Project LoadProject(XmlReader xmlReader, string toolsVersion)
  189. {
  190. return this.LoadProject(xmlReader, null, toolsVersion);
  191. }
  192. public Project LoadProject(string fileName, IDictionary<string, string> globalProperties, string toolsVersion)
  193. {
  194. ErrorUtilities.VerifyThrowArgumentLength(fileName, "fileName");
  195. BuildEventContext buildEventContext = new BuildEventContext(0, -1, -2, -1);
  196. if (globalProperties == null)
  197. {
  198. globalProperties = this.GlobalProperties;
  199. }
  200. else
  201. {
  202. foreach (KeyValuePair<string, string> pair in this.GlobalProperties)
  203. {
  204. if (!globalProperties.ContainsKey(pair.Key))
  205. {
  206. globalProperties.Add(pair);
  207. }
  208. }
  209. }
  210. fileName = FileUtilities.NormalizePath(fileName);
  211. if (toolsVersion == null)
  212. {
  213. try
  214. {
  215. ProjectRootElement element = ProjectRootElement.OpenProjectOrSolution(fileName, globalProperties, toolsVersion, this.LoggingService, this.ProjectRootElementCache, buildEventContext);
  216. toolsVersion = (element.ToolsVersion.Length > 0) ? element.ToolsVersion : this.DefaultToolsVersion;
  217. }
  218. catch (InvalidProjectFileException exception)
  219. {
  220. this.LoggingService.LogInvalidProjectFileError(buildEventContext, exception);
  221. throw;
  222. }
  223. }
  224. Project project = this.loadedProjects.GetMatchingProjectIfAny(fileName, globalProperties, toolsVersion);
  225. if (project == null)
  226. {
  227. project = new Project(fileName, globalProperties, toolsVersion, this);
  228. }
  229. return project;
  230. }
  231. public Project LoadProject(XmlReader xmlReader, IDictionary<string, string> globalProperties, string toolsVersion)
  232. {
  233. return new Project(xmlReader, globalProperties, toolsVersion, this);
  234. }
  235. void IBuildComponent.InitializeComponent(IBuildComponentHost host)
  236. {
  237. this.host = host;
  238. }
  239. void IBuildComponent.ShutdownComponent()
  240. {
  241. this.host = null;
  242. }
  243. internal void OnAfterRenameLoadedProject(string oldFullPathIfAny, Project project)
  244. {
  245. if (project.FullPath != null)
  246. {
  247. if (oldFullPathIfAny != null)
  248. {
  249. ErrorUtilities.VerifyThrowInvalidOperation(this.loadedProjects.RemoveProject(oldFullPathIfAny, project), "OM_ProjectWasNotLoaded");
  250. }
  251. this.loadedProjects.AddProject(project);
  252. if (this.hostServices != null)
  253. {
  254. this.HostServices.OnRenameProject(oldFullPathIfAny, project.FullPath);
  255. }
  256. }
  257. }
  258. public void RegisterForwardingLoggers(IEnumerable<ForwardingLoggerRecord> remoteLoggers)
  259. {
  260. if (remoteLoggers != null)
  261. {
  262. foreach (ForwardingLoggerRecord record in remoteLoggers)
  263. {
  264. this.loggingService.RegisterDistributedLogger(new ReusableLogger(record.CentralLogger), record.ForwardingLoggerDescription);
  265. }
  266. }
  267. }
  268. public void RegisterLogger(ILogger logger)
  269. {
  270. ErrorUtilities.VerifyThrowArgumentNull(logger, "logger");
  271. this.loggingService.RegisterLogger(new ReusableLogger(logger));
  272. }
  273. public void RegisterLoggers(IEnumerable<ILogger> loggers)
  274. {
  275. if (loggers != null)
  276. {
  277. foreach (ILogger logger in loggers)
  278. {
  279. this.RegisterLogger(logger);
  280. }
  281. }
  282. }
  283. public void RemoveAllToolsets()
  284. {
  285. List<Toolset> list = new List<Toolset>(this.Toolsets);
  286. foreach (Toolset toolset in list)
  287. {
  288. this.RemoveToolset(toolset.ToolsVersion);
  289. }
  290. }
  291. public bool RemoveGlobalProperty(string name)
  292. {
  293. bool flag = this.globalProperties.Remove(name);
  294. List<Project> list = new List<Project>(this.loadedProjects);
  295. foreach (Project project in list)
  296. {
  297. project.RemoveGlobalProperty(name);
  298. }
  299. return flag;
  300. }
  301. public bool RemoveToolset(string toolsVersion)
  302. {
  303. ErrorUtilities.VerifyThrowArgumentLength(toolsVersion, "toolsVersion");
  304. if (!this.toolsets.ContainsKey(toolsVersion))
  305. {
  306. return false;
  307. }
  308. this.toolsets.Remove(toolsVersion);
  309. this.toolsetsVersion++;
  310. return true;
  311. }
  312. public void SetGlobalProperty(string name, string value)
  313. {
  314. this.globalProperties.Set(new ProjectPropertyInstance(name, value));
  315. List<Project> list = new List<Project>(this.loadedProjects);
  316. foreach (Project project in list)
  317. {
  318. project.SetGlobalProperty(name, value);
  319. }
  320. }
  321. private void ShutDownLoggingService()
  322. {
  323. if (this.loggingService != null)
  324. {
  325. try
  326. {
  327. ((IBuildComponent) this.LoggingService).ShutdownComponent();
  328. }
  329. catch (LoggerException)
  330. {
  331. throw;
  332. }
  333. catch (InternalLoggerException)
  334. {
  335. throw;
  336. }
  337. catch (Exception exception)
  338. {
  339. ErrorUtilities.ThrowInternalError("Throwing from logger shutdown", exception, new object[0]);
  340. throw;
  341. }
  342. this.loggingService = null;
  343. }
  344. }
  345. public bool TryUnloadProject(ProjectRootElement projectRootElement)
  346. {
  347. ErrorUtilities.VerifyThrowArgumentNull(projectRootElement, "projectRootElement");
  348. this.ProjectRootElementCache.DiscardStrongReferences();
  349. if (this.LoadedProjects.FirstOrDefault<Project>(project => project.UsesProjectRootElement(projectRootElement)) == null)
  350. {
  351. this.ProjectRootElementCache.DiscardAnyWeakReference(projectRootElement);
  352. return true;
  353. }
  354. return false;
  355. }
  356. public static string Unescape(string escapedString)
  357. {
  358. return EscapingUtilities.UnescapeAll(escapedString);
  359. }
  360. public void UnloadAllProjects()
  361. {
  362. foreach (Project project in this.loadedProjects)
  363. {
  364. project.Zombify();
  365. if (this.hostServices != null)
  366. {
  367. this.hostServices.UnregisterProject(project.FullPath);
  368. }
  369. }
  370. this.loadedProjects.RemoveAllProjects();
  371. this.ProjectRootElementCache.Clear();
  372. }
  373. public void UnloadProject(ProjectRootElement projectRootElement)
  374. {
  375. ErrorUtilities.VerifyThrowArgumentNull(projectRootElement, "projectRootElement");
  376. Project project = this.LoadedProjects.FirstOrDefault<Project>(project => project.UsesProjectRootElement(projectRootElement));
  377. if (project != null)
  378. {
  379. ErrorUtilities.ThrowInvalidOperation("OM_ProjectXmlCannotBeUnloadedDueToLoadedProjects", new object[] { projectRootElement.FullPath, project.FullPath });
  380. }
  381. this.ProjectRootElementCache.DiscardAnyWeakReference(projectRootElement);
  382. }
  383. public void UnloadProject(Project project)
  384. {
  385. ErrorUtilities.VerifyThrowInvalidOperation(this.loadedProjects.RemoveProject(project), "OM_ProjectWasNotLoaded");
  386. project.Zombify();
  387. if ((this.hostServices != null) && (this.loadedProjects.GetMatchingProjectsIfAny(project.FullPath).Count == 0))
  388. {
  389. this.hostServices.UnregisterProject(project.FullPath);
  390. }
  391. this.ProjectRootElementCache.DiscardStrongReferences();
  392. }
  393. public void UnregisterAllLoggers()
  394. {
  395. this.loggingService.UnregisterAllLoggers();
  396. this.CreateLoggingService(this.MaxNodeCount, this.OnlyLogCriticalEvents);
  397. }
  398. public int Count
  399. {
  400. get
  401. {
  402. return this.loadedProjects.Count;
  403. }
  404. }
  405. public string DefaultToolsVersion
  406. {
  407. get
  408. {
  409. ErrorUtilities.VerifyThrow(this.defaultToolsVersion != null, "Should have a default");
  410. return this.defaultToolsVersion;
  411. }
  412. set
  413. {
  414. ErrorUtilities.VerifyThrowArgumentLength(value, "DefaultToolsVersion");
  415. if (!this.toolsets.ContainsKey(value))
  416. {
  417. string str = Utilities.CreateToolsVersionListString(this.Toolsets);
  418. ErrorUtilities.ThrowInvalidOperation("UnrecognizedToolsVersion", new object[] { value, str });
  419. }
  420. this.defaultToolsVersion = value;
  421. }
  422. }
  423. public bool DisableMarkDirty
  424. {
  425. [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  426. get
  427. {
  428. return this.<DisableMarkDirty>k__BackingField;
  429. }
  430. [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  431. set
  432. {
  433. this.<DisableMarkDirty>k__BackingField = value;
  434. }
  435. }
  436. internal PropertyDictionary<ProjectPropertyInstance> EnvironmentProperties
  437. {
  438. get
  439. {
  440. if (this.environmentProperties == null)
  441. {
  442. this.environmentProperties = Utilities.GetEnvironmentProperties();
  443. }
  444. return this.environmentProperties;
  445. }
  446. }
  447. public static ProjectCollection GlobalProjectCollection
  448. {
  449. get
  450. {
  451. lock (globalLock)
  452. {
  453. if (globalProjectCollection == null)
  454. {
  455. globalProjectCollection = new ProjectCollection();
  456. }
  457. return globalProjectCollection;
  458. }
  459. }
  460. }
  461. public IDictionary<string, string> GlobalProperties
  462. {
  463. get
  464. {
  465. if (this.globalProperties.Count == 0)
  466. {
  467. return ReadOnlyEmptyDictionary<string, string>.Instance;
  468. }
  469. Dictionary<string, string> backing = new Dictionary<string, string>(this.globalProperties.Count, MSBuildNameIgnoreCaseComparer.Default);
  470. foreach (ProjectPropertyInstance instance in this.globalProperties)
  471. {
  472. backing[instance.Name] = ((IProperty) instance).EvaluatedValueEscaped;
  473. }
  474. return ReadOnlyDictionary<string, string>.CreateWrapper(backing);
  475. }
  476. }
  477. internal PropertyDictionary<ProjectPropertyInstance> GlobalPropertiesCollection
  478. {
  479. [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  480. get
  481. {
  482. return this.globalProperties;
  483. }
  484. }
  485. public Microsoft.Build.Execution.HostServices HostServices
  486. {
  487. get
  488. {
  489. if (this.hostServices == null)
  490. {
  491. this.HostServices = new Microsoft.Build.Execution.HostServices();
  492. }
  493. return this.hostServices;
  494. }
  495. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  496. set
  497. {
  498. this.hostServices = value;
  499. }
  500. }
  501. public bool IsBuildEnabled
  502. {
  503. [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  504. get
  505. {
  506. return this.isBuildEnabled;
  507. }
  508. [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  509. set
  510. {
  511. this.isBuildEnabled = value;
  512. }
  513. }
  514. public ICollection<Project> LoadedProjects
  515. {
  516. get
  517. {
  518. return new ReadOnlyCollection<Project>(this.loadedProjects);
  519. }
  520. }
  521. public ICollection<ILogger> Loggers
  522. {
  523. [DebuggerStepThrough]
  524. get
  525. {
  526. if (this.loggingService.Loggers != null)
  527. {
  528. return new ReadOnlyCollection<ILogger>(this.loggingService.Loggers);
  529. }
  530. return ReadOnlyEmptyCollection<ILogger>.Instance;
  531. }
  532. }
  533. internal ILoggingService LoggingService
  534. {
  535. [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  536. get
  537. {
  538. return this.loggingService;
  539. }
  540. }
  541. internal int MaxNodeCount
  542. {
  543. [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  544. get
  545. {
  546. return this.<MaxNodeCount>k__BackingField;
  547. }
  548. [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  549. set
  550. {
  551. this.<MaxNodeCount>k__BackingField = value;
  552. }
  553. }
  554. public bool OnlyLogCriticalEvents
  555. {
  556. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  557. get
  558. {
  559. return this.onlyLogCriticalEvents;
  560. }
  561. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  562. set
  563. {
  564. this.onlyLogCriticalEvents = value;
  565. }
  566. }
  567. internal Microsoft.Build.Evaluation.ProjectRootElementCache ProjectRootElementCache
  568. {
  569. [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  570. get
  571. {
  572. return this.<ProjectRootElementCache>k__BackingField;
  573. }
  574. [CompilerGenerated]
  575. private set
  576. {
  577. this.<ProjectRootElementCache>k__BackingField = value;
  578. }
  579. }
  580. public bool SkipEvaluation
  581. {
  582. [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  583. get
  584. {
  585. return this.<SkipEvaluation>k__BackingField;
  586. }
  587. [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  588. set
  589. {
  590. this.<SkipEvaluation>k__BackingField = value;
  591. }
  592. }
  593. public ToolsetDefinitionLocations ToolsetLocations
  594. {
  595. [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  596. get
  597. {
  598. return this.toolsetDefinitionLocations;
  599. }
  600. }
  601. public ICollection<Toolset> Toolsets
  602. {
  603. get
  604. {
  605. return this.toolsets.Values;
  606. }
  607. }
  608. internal int ToolsetsVersion
  609. {
  610. [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  611. get
  612. {
  613. return this.toolsetsVersion;
  614. }
  615. }
  616. public static System.Version Version
  617. {
  618. get
  619. {
  620. if (engineVersion == null)
  621. {
  622. engineVersion = new System.Version(FileVersionInfo.GetVersionInfo(new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath).ProductVersion);
  623. }
  624. return engineVersion;
  625. }
  626. }
  627. private class LoadedProjectCollection : IEnumerable<Project>, IEnumerable
  628. {
  629. private int count;
  630. private Dictionary<string, List<Project>> loadedProjects = new Dictionary<string, List<Project>>(StringComparer.OrdinalIgnoreCase);
  631. internal LoadedProjectCollection()
  632. {
  633. }
  634. internal void AddProject(Project project)
  635. {
  636. List<Project> list;
  637. if (!this.loadedProjects.TryGetValue(project.FullPath, out list))
  638. {
  639. list = new List<Project>();
  640. this.loadedProjects.Add(project.FullPath, list);
  641. }
  642. foreach (Project project2 in list)
  643. {
  644. if (this.HasEquivalentGlobalPropertiesAndToolsVersion(project2, project.GlobalProperties, project.ToolsVersion))
  645. {
  646. ErrorUtilities.ThrowInvalidOperation("OM_MatchingProjectAlreadyInCollection", new object[] { project2.FullPath });
  647. }
  648. }
  649. list.Add(project);
  650. this.count++;
  651. }
  652. public IEnumerator<Project> GetEnumerator()
  653. {
  654. foreach (List<Project> iteratorVariable0 in this.loadedProjects.Values)
  655. {
  656. foreach (Project iteratorVariable1 in iteratorVariable0)
  657. {
  658. yield return iteratorVariable1;
  659. }
  660. }
  661. }
  662. internal Project GetMatchingProjectIfAny(string fullPath, IDictionary<string, string> globalProperties, string toolsVersion)
  663. {
  664. List<Project> list;
  665. if (this.loadedProjects.TryGetValue(fullPath, out list))
  666. {
  667. foreach (Project project in list)
  668. {
  669. if (this.HasEquivalentGlobalPropertiesAndToolsVersion(project, globalProperties, toolsVersion))
  670. {
  671. return project;
  672. }
  673. }
  674. }
  675. return null;
  676. }
  677. internal IList<Project> GetMatchingProjectsIfAny(string fullPath)
  678. {
  679. List<Project> list;
  680. this.loadedProjects.TryGetValue(fullPath, out list);
  681. if (list != null)
  682. {
  683. return list;
  684. }
  685. return ReadOnlyEmptyList<Project>.Instance;
  686. }
  687. private bool HasEquivalentGlobalPropertiesAndToolsVersion(Project project, IDictionary<string, string> globalProperties, string toolsVersion)
  688. {
  689. if (!string.Equals(project.ToolsVersion, toolsVersion, StringComparison.OrdinalIgnoreCase))
  690. {
  691. return false;
  692. }
  693. if (project.GlobalProperties.Count != globalProperties.Count)
  694. {
  695. return false;
  696. }
  697. foreach (KeyValuePair<string, string> pair in project.GlobalProperties)
  698. {
  699. string str;
  700. if (!globalProperties.TryGetValue(pair.Key, out str))
  701. {
  702. return false;
  703. }
  704. if (!string.Equals(pair.Value, str, StringComparison.OrdinalIgnoreCase))
  705. {
  706. return false;
  707. }
  708. }
  709. return true;
  710. }
  711. internal void RemoveAllProjects()
  712. {
  713. this.loadedProjects = new Dictionary<string, List<Project>>(StringComparer.OrdinalIgnoreCase);
  714. this.count = 0;
  715. }
  716. internal bool RemoveProject(Project project)
  717. {
  718. return this.RemoveProject(project.FullPath, project);
  719. }
  720. internal bool RemoveProject(string projectFullPath, Project project)
  721. {
  722. List<Project> list;
  723. if (!this.loadedProjects.TryGetValue(projectFullPath, out list))
  724. {
  725. return false;
  726. }
  727. bool flag = list.Remove(project);
  728. if (flag)
  729. {
  730. this.count--;
  731. if (list.Count == 0)
  732. {
  733. this.loadedProjects.Remove(projectFullPath);
  734. }
  735. }
  736. return flag;
  737. }
  738. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  739. IEnumerator IEnumerable.GetEnumerator()
  740. {
  741. return this.GetEnumerator();
  742. }
  743. internal int Count
  744. {
  745. get
  746. {
  747. return this.count;
  748. }
  749. }
  750. }
  751. internal class ReusableLogger : INodeLogger, ILogger, IEventSource
  752. {
  753. private AnyEventHandler anyEventHandler;
  754. private AnyEventHandler AnyEventRaised;
  755. private BuildErrorEventHandler buildErrorEventHandler;
  756. private BuildFinishedEventHandler BuildFinished;
  757. private BuildFinishedEventHandler buildFinishedEventHandler;
  758. private BuildMessageEventHandler buildMessageEventHandler;
  759. private BuildStartedEventHandler BuildStarted;
  760. private BuildStartedEventHandler buildStartedEventHandler;
  761. private BuildStatusEventHandler buildStatusEventHandler;
  762. private IEventSource buildTimeEventSource;
  763. private BuildWarningEventHandler buildWarningEventHandler;
  764. private CustomBuildEventHandler customBuildEventHandler;
  765. private CustomBuildEventHandler CustomEventRaised;
  766. private IEventSource designTimeEventSource;
  767. private BuildErrorEventHandler ErrorRaised;
  768. private BuildMessageEventHandler MessageRaised;
  769. private ILogger originalLogger;
  770. private ProjectFinishedEventHandler ProjectFinished;
  771. private ProjectFinishedEventHandler projectFinishedEventHandler;
  772. private ProjectStartedEventHandler ProjectStarted;
  773. private ProjectStartedEventHandler projectStartedEventHandler;
  774. private BuildStatusEventHandler StatusEventRaised;
  775. private TargetFinishedEventHandler TargetFinished;
  776. private TargetFinishedEventHandler targetFinishedEventHandler;
  777. private TargetStartedEventHandler TargetStarted;
  778. private TargetStartedEventHandler targetStartedEventHandler;
  779. private TaskFinishedEventHandler TaskFinished;
  780. private TaskFinishedEventHandler taskFinishedEventHandler;
  781. private TaskStartedEventHandler TaskStarted;
  782. private TaskStartedEventHandler taskStartedEventHandler;
  783. private BuildWarningEventHandler WarningRaised;
  784. public event AnyEventHandler AnyEventRaised
  785. {
  786. add
  787. {
  788. AnyEventHandler handler2;
  789. AnyEventHandler anyEventRaised = this.AnyEventRaised;
  790. do
  791. {
  792. handler2 = anyEventRaised;
  793. AnyEventHandler handler3 = (AnyEventHandler) Delegate.Combine(handler2, value);
  794. anyEventRaised = Interlocked.CompareExchange<AnyEventHandler>(ref this.AnyEventRaised, handler3, handler2);
  795. }
  796. while (anyEventRaised != handler2);
  797. }
  798. remove
  799. {
  800. AnyEventHandler handler2;
  801. AnyEventHandler anyEventRaised = this.AnyEventRaised;
  802. do
  803. {
  804. handler2 = anyEventRaised;
  805. AnyEventHandler handler3 = (AnyEventHandler) Delegate.Remove(handler2, value);
  806. anyEventRaised = Interlocked.CompareExchange<AnyEventHandler>(ref this.AnyEventRaised, handler3, handler2);
  807. }
  808. while (anyEventRaised != handler2);
  809. }
  810. }
  811. public event BuildFinishedEventHandler BuildFinished
  812. {
  813. add
  814. {
  815. BuildFinishedEventHandler handler2;
  816. BuildFinishedEventHandler buildFinished = this.BuildFinished;
  817. do
  818. {
  819. handler2 = buildFinished;
  820. BuildFinishedEventHandler handler3 = (BuildFinishedEventHandler) Delegate.Combine(handler2, value);
  821. buildFinished = Interlocked.CompareExchange<BuildFinishedEventHandler>(ref this.BuildFinished, handler3, handler2);
  822. }
  823. while (buildFinished != handler2);
  824. }
  825. remove
  826. {
  827. BuildFinishedEventHandler handler2;
  828. BuildFinishedEventHandler buildFinished = this.BuildFinished;
  829. do
  830. {
  831. handler2 = buildFinished;
  832. BuildFinishedEventHandler handler3 = (BuildFinishedEventHandler) Delegate.Remove(handler2, value);
  833. buildFinished = Interlocked.CompareExchange<BuildFinishedEventHandler>(ref this.BuildFinished, handler3, handler2);
  834. }
  835. while (buildFinished != handler2);
  836. }
  837. }
  838. public event BuildStartedEventHandler BuildStarted
  839. {
  840. add
  841. {
  842. BuildStartedEventHandler handler2;
  843. BuildStartedEventHandler buildStarted = this.BuildStarted;
  844. do
  845. {
  846. handler2 = buildStarted;
  847. BuildStartedEventHandler handler3 = (BuildStartedEventHandler) Delegate.Combine(handler2, value);
  848. buildStarted = Interlocked.CompareExchange<BuildStartedEventHandler>(ref this.BuildStarted, handler3, handler2);
  849. }
  850. while (buildStarted != handler2);
  851. }
  852. remove
  853. {
  854. BuildStartedEventHandler handler2;
  855. BuildStartedEventHandler buildStarted = this.BuildStarted;
  856. do
  857. {
  858. handler2 = buildStarted;
  859. BuildStartedEventHandler handler3 = (BuildStartedEventHandler) Delegate.Remove(handler2, value);
  860. buildStarted = Interlocked.CompareExchange<BuildStartedEventHandler>(ref this.BuildStarted, handler3, handler2);
  861. }
  862. while (buildStarted != handler2);
  863. }
  864. }
  865. public event CustomBuildEventHandler CustomEventRaised
  866. {
  867. add
  868. {
  869. CustomBuildEventHandler handler2;
  870. CustomBuildEventHandler customEventRaised = this.CustomEventRaised;
  871. do
  872. {
  873. handler2 = customEventRaised;
  874. CustomBuildEventHandler handler3 = (CustomBuildEventHandler) Delegate.Combine(handler2, value);
  875. customEventRaised = Interlocked.CompareExchange<CustomBuildEventHandler>(ref this.CustomEventRaised, handler3, handler2);
  876. }
  877. while (customEventRaised != handler2);
  878. }
  879. remove
  880. {
  881. CustomBuildEventHandler handler2;
  882. CustomBuildEventHandler customEventRaised = this.CustomEventRaised;
  883. do
  884. {
  885. handler2 = customEventRaised;
  886. CustomBuildEventHandler handler3 = (CustomBuildEventHandler) Delegate.Remove(handler2, value);
  887. customEventRaised = Interlocked.CompareExchange<CustomBuildEventHandler>(ref this.CustomEventRaised, handler3, handler2);
  888. }
  889. while (customEventRaised != handler2);
  890. }
  891. }
  892. public event BuildErrorEventHandler ErrorRaised
  893. {
  894. add
  895. {
  896. BuildErrorEventHandler handler2;
  897. BuildErrorEventHandler errorRaised = this.ErrorRaised;
  898. do
  899. {
  900. handler2 = errorRaised;
  901. BuildErrorEventHandler handler3 = (BuildErrorEventHandler) Delegate.Combine(handler2, value);
  902. errorRaised = Interlocked.CompareExchange<BuildErrorEventHandler>(ref this.ErrorRaised, handler3, handler2);
  903. }
  904. while (errorRaised != handler2);
  905. }
  906. remove
  907. {
  908. BuildErrorEventHandler handler2;
  909. BuildErrorEventHandler errorRaised = this.ErrorRaised;
  910. do
  911. {
  912. handler2 = errorRaised;
  913. BuildErrorEventHandler handler3 = (BuildErrorEventHandler) Delegate.Remove(handler2, value);
  914. errorRaised = Interlocked.CompareExchange<BuildErrorEventHandler>(ref this.ErrorRaised, handler3, handler2);
  915. }
  916. while (errorRaised != handler2);
  917. }
  918. }
  919. public event BuildMessageEventHandler MessageRaised
  920. {
  921. add
  922. {
  923. BuildMessageEventHandler handler2;
  924. BuildMessageEventHandler messageRaised = this.MessageRaised;
  925. do
  926. {
  927. handler2 = messageRaised;
  928. BuildMessageEventHandler handler3 = (BuildMessageEventHandler) Delegate.Combine(handler2, value);
  929. messageRaised = Interlocked.CompareExchange<BuildMessageEventHandler>(ref this.MessageRaised, handler3, handler2);
  930. }
  931. while (messageRaised != handler2);
  932. }
  933. remove
  934. {
  935. BuildMessageEventHandler handler2;
  936. BuildMessageEventHandler messageRaised = this.MessageRaised;
  937. do
  938. {
  939. handler2 = messageRaised;
  940. BuildMessageEventHandler handler3 = (BuildMessageEventHandler) Delegate.Remove(handler2, value);
  941. messageRaised = Interlocked.CompareExchange<BuildMessageEventHandler>(ref this.MessageRaised, handler3, handler2);
  942. }
  943. while (messageRaised != handler2);
  944. }
  945. }
  946. public event ProjectFinishedEventHandler ProjectFinished
  947. {
  948. add
  949. {
  950. ProjectFinishedEventHandler handler2;
  951. ProjectFinishedEventHandler projectFinished = this.ProjectFinished;
  952. do
  953. {
  954. handler2 = projectFinished;
  955. ProjectFinishedEventHandler handler3 = (ProjectFinishedEventHandler) Delegate.Combine(handler2, value);
  956. projectFinished = Interlocked.CompareExchange<ProjectFinishedEventHandler>(ref this.ProjectFinished, handler3, handler2);
  957. }
  958. while (projectFinished != handler2);
  959. }
  960. remove
  961. {
  962. ProjectFinishedEventHandler handler2;
  963. ProjectFinishedEventHandler projectFinished = this.ProjectFinished;
  964. do
  965. {
  966. handler2 = projectFinished;
  967. ProjectFinishedEventHandler handler3 = (ProjectFinishedEventHandler) Delegate.Remove(handler2, value);
  968. projectFinished = Interlocked.CompareExchange<ProjectFinishedEventHandler>(ref this.ProjectFinished, handler3, handler2);
  969. }
  970. while (projectFinished != handler2);
  971. }
  972. }
  973. public event ProjectStartedEventHandler ProjectStarted
  974. {
  975. add
  976. {
  977. ProjectStartedEventHandler handler2;
  978. ProjectStartedEventHandler projectStarted = this.ProjectStarted;
  979. do
  980. {
  981. handler2 = projectStarted;
  982. ProjectStartedEventHandler handler3 = (ProjectStartedEventHandler) Delegate.Combine(handler2, value);
  983. projectStarted = Interlocked.CompareExchange<ProjectStartedEventHandler>(ref this.ProjectStarted, handler3, handler2);
  984. }
  985. while (projectStarted != handler2);
  986. }
  987. remove
  988. {
  989. ProjectStartedEventHandler handler2;
  990. ProjectStartedEventHandler projectStarted = this.ProjectStarted;
  991. do
  992. {
  993. handler2 = projectStarted;
  994. ProjectStartedEventHandler handler3 = (ProjectStartedEventHandler) Delegate.Remove(handler2, value);
  995. projectStarted = Interlocked.CompareExchange<ProjectStartedEventHandler>(ref this.ProjectStarted, handler3, handler2);
  996. }
  997. while (projectStarted != handler2);
  998. }
  999. }
  1000. public event BuildStatusEventHandler StatusEventRaised
  1001. {
  1002. add
  1003. {
  1004. BuildStatusEventHandler handler2;
  1005. BuildStatusEventHandler statusEventRaised = this.StatusEventRaised;
  1006. do
  1007. {
  1008. handler2 = statusEventRaised;
  1009. BuildStatusEventHandler handler3 = (BuildStatusEventHandler) Delegate.Combine(handler2, value);
  1010. statusEventRaised = Interlocked.CompareExchange<BuildStatusEventHandler>(ref this.StatusEventRaised, handler3, handler2);
  1011. }
  1012. while (statusEventRaised != handler2);
  1013. }
  1014. remove
  1015. {
  1016. BuildStatusEventHandler handler2;
  1017. BuildStatusEventHandler statusEventRaised = this.StatusEventRaised;
  1018. do
  1019. {
  1020. handler2 = statusEventRaised;
  1021. BuildStatusEventHandler handler3 = (BuildStatusEventHandler) Delegate.Remove(handler2, value);
  1022. statusEventRaised = Interlocked.CompareExchange<BuildStatusEventHandler>(ref this.StatusEventRaised, handler3, handler2);
  1023. }
  1024. while (statusEventRaised != handler2);
  1025. }
  1026. }
  1027. public event TargetFinishedEventHandler TargetFinished
  1028. {
  1029. add
  1030. {
  1031. TargetFinishedEventHandler handler2;
  1032. TargetFinishedEventHandler targetFinished = this.TargetFinished;
  1033. do
  1034. {
  1035. handler2 = targetFinished;
  1036. TargetFinishedEventHandler handler3 = (TargetFinishedEventHandler) Delegate.Combine(handler2, value);
  1037. targetFinished = Interlocked.CompareExchange<TargetFinishedEventHandler>(ref this.TargetFinished, handler3, handler2);
  1038. }
  1039. while (targetFinished != handler2);
  1040. }
  1041. remove
  1042. {
  1043. TargetFinishedEventHandler handler2;
  1044. TargetFinishedEventHandler targetFinished = this.TargetFinished;
  1045. do
  1046. {
  1047. handler2 = targetFinished;
  1048. TargetFinishedEventHandler handler3 = (TargetFinishedEventHandler) Delegate.Remove(handler2, value);
  1049. targetFinished = Interlocked.CompareExchange<TargetFinishedEventHandler>(ref this.TargetFinished, handler3, handler2);
  1050. }
  1051. while (targetFinished != handler2);
  1052. }
  1053. }
  1054. public event TargetStartedEventHandler TargetStarted
  1055. {
  1056. add
  1057. {
  1058. TargetStartedEventHandler handler2;
  1059. TargetStartedEventHandler targetStarted = this.TargetStarted;
  1060. do
  1061. {
  1062. handler2 = targetStarted;
  1063. TargetStartedEventHandler handler3 = (TargetStartedEventHandler) Delegate.Combine(handler2, value);
  1064. targetStarted = Interlocked.CompareExchange<TargetStartedEventHandler>(ref this.TargetStarted, handler3, handler2);
  1065. }
  1066. while (targetStarted != handler2);
  1067. }
  1068. remove
  1069. {
  1070. TargetStartedEventHandler handler2;
  1071. TargetStartedEventHandler targetStarted = this.TargetStarted;
  1072. do
  1073. {
  1074. handler2 = targetStarted;
  1075. TargetStartedEventHandler handler3 = (TargetStartedEventHandler) Delegate.Remove(handler2, value);
  1076. targetStarted = Interlocked.CompareExchange<TargetStartedEventHandler>(ref this.TargetStarted, handler3, handler2);
  1077. }
  1078. while (targetStarted != handler2);
  1079. }
  1080. }
  1081. public event TaskFinishedEventHandler TaskFinished
  1082. {
  1083. add
  1084. {
  1085. TaskFinishedEventHandler handler2;
  1086. TaskFinishedEventHandler taskFinished = this.TaskFinished;
  1087. do
  1088. {
  1089. handler2 = taskFinished;
  1090. TaskFinishedEventHandler handler3 = (TaskFinishedEventHandler) Delegate.Combine(handler2, value);
  1091. taskFinished = Interlocked.CompareExchange<TaskFinishedEventHandler>(ref this.TaskFinished, handler3, handl

Large files files are truncated, but you can click here to view the full file