/Microsoft.Build/Microsoft.Build/Microsoft/Build/Evaluation/Evaluator!4.cs
C# | 1192 lines | 1152 code | 40 blank | 0 comment | 203 complexity | fe8675671206865b6c4e11eb12d33ea8 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0
Large files files are truncated, but you can click here to view the full file
- namespace Microsoft.Build.Evaluation
- {
- using Microsoft.Build.BackEnd;
- using Microsoft.Build.BackEnd.Logging;
- using Microsoft.Build.Collections;
- using Microsoft.Build.Construction;
- using Microsoft.Build.Debugging;
- using Microsoft.Build.Exceptions;
- using Microsoft.Build.Execution;
- using Microsoft.Build.Framework;
- using Microsoft.Build.Internal;
- using Microsoft.Build.Shared;
- using Microsoft.Internal.Performance;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Runtime;
- using System.Runtime.CompilerServices;
-
- internal class Evaluator<P, I, M, D> where P: class, IProperty, IEquatable<P>, IValued where I: class, IItem<M>, IMetadataTable where M: class, IMetadatum where D: class, IItemDefinition<M>
- {
- private BuildEventContext buildEventContext;
- private readonly IEvaluatorData<P, I, M, D> data;
- private static readonly bool debugEvaluation;
- private readonly PropertyDictionary<ProjectPropertyInstance> environmentProperties;
- private readonly Expander<P, I> expander;
- private IDictionary<ProjectRootElement, ProjectRootElement> importRelationships;
- private readonly Dictionary<string, ProjectImportElement> importsSeen;
- private IDictionary<string, object> initialLocals;
- private static IList<DebuggerLocalType> initialLocalsTypes;
- private readonly List<string> initialTargetsList;
- private readonly IList<ProjectItemDefinitionGroupElement> itemDefinitionGroupElements;
- private IDictionary<string, object> itemDefinitionPassLocals;
- private static IList<DebuggerLocalType> itemDefinitionPassLocalsTypes;
- private readonly IItemFactory<I, I> itemFactory;
- private readonly IList<ProjectItemGroupElement> itemGroupElements;
- private IDictionary<string, object> itemPassLocals;
- private static IList<DebuggerLocalType> itemPassLocalsTypes;
- private readonly ProjectLoadSettings loadSettings;
- private readonly ILoggingService loggingService;
- private readonly int maxNodeCount;
- private readonly ProjectInstance projectInstanceIfAnyForDebuggerOnly;
- private IDictionary<string, object> projectLevelLocalsForBuild;
- private readonly ProjectRootElement projectRootElement;
- private readonly ProjectRootElementCache projectRootElementCache;
- private readonly Dictionary<ProjectRootElement, NGen<bool>> projectSupportsReturnsAttribute;
- private IDictionary<string, object> propertyPassLocals;
- private static IList<DebuggerLocalType> propertyPassLocalsTypes;
- private static readonly char[] splitter;
- private readonly IList<ProjectTargetElement> targetElements;
- private readonly IList<Pair<string, ProjectUsingTaskElement>> usingTaskElements;
-
- static Evaluator()
- {
- Evaluator<P, I, M, D>.splitter = new char[] { ';' };
- Evaluator<P, I, M, D>.debugEvaluation = Environment.GetEnvironmentVariable("MSBUILDDEBUGEVALUATION") != null;
- }
-
- private Evaluator(IEvaluatorData<P, I, M, D> data, ProjectRootElement projectRootElement, ProjectLoadSettings loadSettings, int maxNodeCount, PropertyDictionary<ProjectPropertyInstance> environmentProperties, ILoggingService loggingService, IItemFactory<I, I> itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCache projectRootElementCache, BuildEventContext buildEventContext, ProjectInstance projectInstanceIfAnyForDebuggerOnly)
- {
- ErrorUtilities.VerifyThrowInternalNull(data, "data");
- ErrorUtilities.VerifyThrowInternalNull(projectRootElementCache, "projectRootElementCache");
- data.InitializeForEvaluation(toolsetProvider);
- this.expander = new Expander<P, I>(data, data);
- this.expander.WarnForUninitializedProperties = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("MSBUILDWARNONUNINITIALIZEDPROPERTY"));
- this.data = data;
- this.itemGroupElements = new List<ProjectItemGroupElement>();
- this.itemDefinitionGroupElements = new List<ProjectItemDefinitionGroupElement>();
- this.usingTaskElements = new List<Pair<string, ProjectUsingTaskElement>>();
- this.targetElements = new List<ProjectTargetElement>();
- this.importsSeen = new Dictionary<string, ProjectImportElement>(StringComparer.OrdinalIgnoreCase);
- this.initialTargetsList = new List<string>();
- this.projectSupportsReturnsAttribute = new Dictionary<ProjectRootElement, NGen<bool>>();
- this.projectRootElement = projectRootElement;
- this.loadSettings = loadSettings;
- this.maxNodeCount = maxNodeCount;
- this.environmentProperties = environmentProperties;
- this.loggingService = loggingService;
- this.itemFactory = itemFactory;
- this.projectRootElementCache = projectRootElementCache;
- this.buildEventContext = buildEventContext;
- this.projectInstanceIfAnyForDebuggerOnly = projectInstanceIfAnyForDebuggerOnly;
- }
-
- private void AddBeforeAndAfterTargetMappings(ProjectTargetElement targetElement, Dictionary<string, LinkedListNode<ProjectTargetElement>> activeTargets, Dictionary<string, List<TargetSpecification>> targetsWhichRunBeforeByTarget, Dictionary<string, List<TargetSpecification>> targetsWhichRunAfterByTarget)
- {
- IList<string> list = this.expander.ExpandIntoStringListLeaveEscaped(targetElement.BeforeTargets, ExpanderOptions.ExpandPropertiesAndItems, targetElement.BeforeTargetsLocation);
- IList<string> list2 = this.expander.ExpandIntoStringListLeaveEscaped(targetElement.AfterTargets, ExpanderOptions.ExpandPropertiesAndItems, targetElement.AfterTargetsLocation);
- foreach (string str in list)
- {
- string key = EscapingUtilities.UnescapeAll(str);
- if (activeTargets.ContainsKey(key))
- {
- List<TargetSpecification> list3 = null;
- if (!targetsWhichRunBeforeByTarget.TryGetValue(key, out list3))
- {
- list3 = new List<TargetSpecification>();
- targetsWhichRunBeforeByTarget[key] = list3;
- }
- list3.Add(new TargetSpecification(targetElement.Name, targetElement.BeforeTargetsLocation));
- continue;
- }
- this.loggingService.LogWarning(this.buildEventContext, null, new BuildEventFileInfo(targetElement.BeforeTargetsLocation), "TargetDoesNotExist", new object[] { key });
- }
- foreach (string str3 in list2)
- {
- string str4 = EscapingUtilities.UnescapeAll(str3);
- if (activeTargets.ContainsKey(str4))
- {
- List<TargetSpecification> list4 = null;
- if (!targetsWhichRunAfterByTarget.TryGetValue(str4, out list4))
- {
- list4 = new List<TargetSpecification>();
- targetsWhichRunAfterByTarget[str4] = list4;
- }
- list4.Add(new TargetSpecification(targetElement.Name, targetElement.AfterTargetsLocation));
- continue;
- }
- this.loggingService.LogWarning(this.buildEventContext, null, new BuildEventFileInfo(targetElement.AfterTargetsLocation), "TargetDoesNotExist", new object[] { str4 });
- }
- }
-
- private ICollection<P> AddBuiltInProperties()
- {
- string startupDirectory = BuildParameters.StartupDirectory;
- List<P> list = new List<P>(12) {
- this.SetBuiltInProperty("MSBuildToolsVersion", this.data.Toolset.ToolsVersion),
- this.SetBuiltInProperty("MSBuildToolsPath", this.data.Toolset.ToolsPath),
- this.SetBuiltInProperty("MSBuildBinPath", this.data.Toolset.ToolsPath),
- this.SetBuiltInProperty("MSBuildStartupDirectory", startupDirectory),
- this.SetBuiltInProperty("MSBuildNodeCount", this.maxNodeCount.ToString(CultureInfo.CurrentCulture)),
- this.SetBuiltInProperty("MSBuildProgramFiles32", FrameworkLocationHelper.programFiles32)
- };
- if (string.IsNullOrEmpty(this.projectRootElement.FullPath))
- {
- if (string.IsNullOrEmpty(this.projectRootElement.DirectoryPath))
- {
- list.Add(this.SetBuiltInProperty("MSBuildProjectDirectory", startupDirectory));
- return list;
- }
- list.Add(this.SetBuiltInProperty("MSBuildProjectDirectory", this.projectRootElement.DirectoryPath));
- return list;
- }
- string evaluatedValueEscaped = EscapingUtilities.Escape(Path.GetFileName(this.projectRootElement.FullPath));
- string str3 = EscapingUtilities.Escape(Path.GetFileNameWithoutExtension(this.projectRootElement.FullPath));
- string str4 = EscapingUtilities.Escape(Path.GetExtension(this.projectRootElement.FullPath));
- string str5 = EscapingUtilities.Escape(this.projectRootElement.FullPath);
- string path = EscapingUtilities.Escape(this.projectRootElement.DirectoryPath);
- int length = Path.GetPathRoot(path).Length;
- string str7 = EscapingUtilities.Escape(FileUtilities.EnsureNoLeadingSlash(FileUtilities.EnsureNoTrailingSlash(path.Substring(length))));
- list.Add(this.SetBuiltInProperty("MSBuildProjectFile", evaluatedValueEscaped));
- list.Add(this.SetBuiltInProperty("MSBuildProjectName", str3));
- list.Add(this.SetBuiltInProperty("MSBuildProjectExtension", str4));
- list.Add(this.SetBuiltInProperty("MSBuildProjectFullPath", str5));
- list.Add(this.SetBuiltInProperty("MSBuildProjectDirectory", path));
- list.Add(this.SetBuiltInProperty("MSBuildProjectDirectoryNoRoot", str7));
- return list;
- }
-
- private ICollection<P> AddEnvironmentProperties()
- {
- List<P> list = new List<P>(this.environmentProperties.Count);
- foreach (ProjectPropertyInstance instance in this.environmentProperties)
- {
- P item = this.data.SetProperty(instance.Name, ((IProperty) instance).EvaluatedValueEscaped, false, false);
- list.Add(item);
- }
- return list;
- }
-
- private ICollection<P> AddGlobalProperties()
- {
- if (this.data.GlobalPropertiesDictionary == null)
- {
- return ReadOnlyEmptyList<P>.Instance;
- }
- List<P> list = new List<P>(this.data.GlobalPropertiesDictionary.Count);
- foreach (ProjectPropertyInstance instance in this.data.GlobalPropertiesDictionary)
- {
- P item = this.data.SetProperty(instance.Name, ((IProperty) instance).EvaluatedValueEscaped, true, false);
- list.Add(item);
- }
- return list;
- }
-
- private ICollection<P> AddToolsetProperties()
- {
- List<P> list = new List<P>(this.data.Toolset.Properties.Count);
- foreach (ProjectPropertyInstance instance in this.data.Toolset.Properties.Values)
- {
- P item = this.data.SetProperty(instance.Name, ((IProperty) instance).EvaluatedValueEscaped, false, false);
- list.Add(item);
- }
- return list;
- }
-
- internal static List<I> CreateItemsFromInclude(string rootDirectory, ProjectItemElement itemElement, IItemFactory<I, I> itemFactory, string unevaluatedIncludeEscaped, Expander<P, I> expander)
- {
- ErrorUtilities.VerifyThrowArgumentLength(unevaluatedIncludeEscaped, "unevaluatedIncludeEscaped");
- List<I> list = new List<I>();
- itemFactory.ItemElement = itemElement;
- string expression = expander.ExpandIntoStringLeaveEscaped(unevaluatedIncludeEscaped, ExpanderOptions.ExpandProperties, itemElement.IncludeLocation);
- if (expression.Length > 0)
- {
- foreach (string str2 in ExpressionShredder.SplitSemiColonSeparatedList(expression))
- {
- bool flag;
- IList<I> list3 = expander.ExpandSingleItemVectorExpressionIntoItems<I>(str2, itemFactory, ExpanderOptions.ExpandItems, false, out flag, itemElement.IncludeLocation);
- if (list3 != null)
- {
- foreach (I local in list3)
- {
- list.Add(local);
- }
- continue;
- }
- string[] fileListEscaped = EngineFileUtilities.GetFileListEscaped(rootDirectory, str2);
- if (fileListEscaped.Length > 0)
- {
- foreach (string str3 in fileListEscaped)
- {
- list.Add(itemFactory.CreateItem(str3, str2));
- }
- }
- }
- }
- return list;
- }
-
- private IDictionary<string, object> Evaluate()
- {
- Evaluator<P, I, M, D>.InitializeForDebugging();
- ICollection<P> is2 = this.AddBuiltInProperties();
- ICollection<P> is3 = this.AddEnvironmentProperties();
- ICollection<P> is4 = this.AddToolsetProperties();
- ICollection<P> is5 = this.AddGlobalProperties();
- if (DebuggerManager.DebuggingEnabled)
- {
- this.initialLocals = new Dictionary<string, object>();
- DebuggerLocalType type = Evaluator<P, I, M, D>.initialLocalsTypes[0];
- this.initialLocals.Add(new KeyValuePair<string, object>(type.Name, this.projectInstanceIfAnyForDebuggerOnly));
- DebuggerLocalType type2 = Evaluator<P, I, M, D>.initialLocalsTypes[1];
- this.initialLocals.Add(new KeyValuePair<string, object>(type2.Name, is2));
- DebuggerLocalType type3 = Evaluator<P, I, M, D>.initialLocalsTypes[2];
- this.initialLocals.Add(new KeyValuePair<string, object>(type3.Name, is3));
- DebuggerLocalType type4 = Evaluator<P, I, M, D>.initialLocalsTypes[3];
- this.initialLocals.Add(new KeyValuePair<string, object>(type4.Name, is4));
- DebuggerLocalType type5 = Evaluator<P, I, M, D>.initialLocalsTypes[4];
- this.initialLocals.Add(new KeyValuePair<string, object>(type5.Name, is5));
- DebuggerManager.DefineState(this.projectRootElement.Location, this.projectRootElement.ElementName, Evaluator<P, I, M, D>.initialLocalsTypes);
- DebuggerManager.BakeStates(Path.GetFileNameWithoutExtension(this.projectRootElement.FullPath));
- DebuggerManager.PulseState(this.projectRootElement.Location, this.initialLocals);
- this.propertyPassLocals = new Dictionary<string, object>(this.initialLocals);
- DebuggerLocalType type6 = Evaluator<P, I, M, D>.propertyPassLocalsTypes[5];
- this.propertyPassLocals.Add(new KeyValuePair<string, object>(type6.Name, new ExpandExpression<P, I, M, D>(this.data.ExpandString)));
- DebuggerLocalType type7 = Evaluator<P, I, M, D>.propertyPassLocalsTypes[6];
- this.propertyPassLocals.Add(new KeyValuePair<string, object>(type7.Name, new EvaluateConditionalExpression<P, I, M, D>(this.data.EvaluateCondition)));
- DebuggerLocalType type8 = Evaluator<P, I, M, D>.propertyPassLocalsTypes[7];
- this.propertyPassLocals.Add(new KeyValuePair<string, object>(type8.Name, this.data.Toolset.ToolsVersion));
- DebuggerLocalType type9 = Evaluator<P, I, M, D>.propertyPassLocalsTypes[8];
- this.propertyPassLocals.Add(new KeyValuePair<string, object>(type9.Name, this.data.Properties));
- this.itemDefinitionPassLocals = new Dictionary<string, object>(this.propertyPassLocals);
- DebuggerLocalType type10 = Evaluator<P, I, M, D>.itemDefinitionPassLocalsTypes[9];
- this.itemDefinitionPassLocals.Add(new KeyValuePair<string, object>(type10.Name, this.data.ItemDefinitionsEnumerable));
- this.itemPassLocals = new Dictionary<string, object>(this.itemDefinitionPassLocals);
- DebuggerLocalType type11 = Evaluator<P, I, M, D>.itemPassLocalsTypes[10];
- this.itemPassLocals.Add(new KeyValuePair<string, object>(type11.Name, this.data.Items));
- this.importRelationships = new Dictionary<ProjectRootElement, ProjectRootElement>();
- this.projectLevelLocalsForBuild = this.itemPassLocals;
- }
- Microsoft.Internal.Performance.CodeMarkers.Instance.CodeMarker(Microsoft.Internal.Performance.CodeMarkerEvent.perfMSBuildProjectEvaluatePass0End);
- if (!string.IsNullOrEmpty(this.projectRootElement.ProjectFileLocation.File))
- {
- string file = this.projectRootElement.ProjectFileLocation.File;
- }
- this.PerformDepthFirstPass(this.projectRootElement);
- List<string> list = new List<string>(this.initialTargetsList.Count);
- for (int i = 0; i < this.initialTargetsList.Count; i++)
- {
- list.Add(EscapingUtilities.UnescapeAll(this.initialTargetsList[i].Trim()));
- }
- this.data.InitialTargets = list;
- Microsoft.Internal.Performance.CodeMarkers.Instance.CodeMarker(Microsoft.Internal.Performance.CodeMarkerEvent.perfMSBuildProjectEvaluatePass1End);
- foreach (ProjectItemDefinitionGroupElement element in this.itemDefinitionGroupElements)
- {
- this.EvaluateItemDefinitionGroupElement(element);
- }
- Microsoft.Internal.Performance.CodeMarkers.Instance.CodeMarker(Microsoft.Internal.Performance.CodeMarkerEvent.perfMSBuildProjectEvaluatePass2End);
- foreach (ProjectItemGroupElement element2 in this.itemGroupElements)
- {
- this.EvaluateItemGroupElement(element2);
- }
- Microsoft.Internal.Performance.CodeMarkers.Instance.CodeMarker(Microsoft.Internal.Performance.CodeMarkerEvent.perfMSBuildProjectEvaluatePass3End);
- foreach (Pair<string, ProjectUsingTaskElement> pair in this.usingTaskElements)
- {
- this.EvaluateUsingTaskElement(pair.Key, pair.Value);
- }
- if ((this.data.DefaultTargets == null) || (this.data.DefaultTargets.Count == 0))
- {
- List<string> list2 = new List<string>(this.targetElements.Count);
- if (this.targetElements.Count > 0)
- {
- list2.Add(this.targetElements[0].Name);
- }
- this.data.DefaultTargets = list2;
- }
- Dictionary<string, List<TargetSpecification>> targetsWhichRunBeforeByTarget = new Dictionary<string, List<TargetSpecification>>(StringComparer.OrdinalIgnoreCase);
- Dictionary<string, List<TargetSpecification>> targetsWhichRunAfterByTarget = new Dictionary<string, List<TargetSpecification>>(StringComparer.OrdinalIgnoreCase);
- LinkedList<ProjectTargetElement> activeTargetsByEvaluationOrder = new LinkedList<ProjectTargetElement>();
- Dictionary<string, LinkedListNode<ProjectTargetElement>> activeTargets = new Dictionary<string, LinkedListNode<ProjectTargetElement>>(StringComparer.OrdinalIgnoreCase);
- Microsoft.Internal.Performance.CodeMarkers.Instance.CodeMarker(Microsoft.Internal.Performance.CodeMarkerEvent.perfMSBuildProjectEvaluatePass4End);
- foreach (ProjectTargetElement element3 in this.targetElements)
- {
- this.ReadTargetElement(element3, activeTargetsByEvaluationOrder, activeTargets);
- }
- foreach (ProjectTargetElement element4 in activeTargetsByEvaluationOrder)
- {
- this.AddBeforeAndAfterTargetMappings(element4, activeTargets, targetsWhichRunBeforeByTarget, targetsWhichRunAfterByTarget);
- }
- this.data.BeforeTargets = targetsWhichRunBeforeByTarget;
- this.data.AfterTargets = targetsWhichRunAfterByTarget;
- if (Evaluator<P, I, M, D>.debugEvaluation && (this.projectRootElement.Count > 0))
- {
- ProjectPropertyInstance instance = this.data.GlobalPropertiesDictionary["currentsolutionconfigurationcontents"];
- if (instance != null)
- {
- instance.EvaluatedValue.GetHashCode();
- }
- }
- return this.projectLevelLocalsForBuild;
- }
-
- internal static IDictionary<string, object> Evaluate(IEvaluatorData<P, I, M, D> data, ProjectRootElement root, ProjectLoadSettings loadSettings, int maxNodeCount, PropertyDictionary<ProjectPropertyInstance> environmentProperties, ILoggingService loggingService, IItemFactory<I, I> itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCache projectRootElementCache, BuildEventContext buildEventContext, ProjectInstance projectInstanceIfAnyForDebuggerOnly)
- {
- using (new Microsoft.Internal.Performance.CodeMarkerStartEnd(Microsoft.Internal.Performance.CodeMarkerEvent.perfMSBuildProjectEvaluateBegin, Microsoft.Internal.Performance.CodeMarkerEvent.perfMSBuildProjectEvaluateEnd))
- {
- Evaluator<P, I, M, D> evaluator = new Evaluator<P, I, M, D>(data, root, loadSettings, maxNodeCount, environmentProperties, loggingService, itemFactory, toolsetProvider, projectRootElementCache, buildEventContext, projectInstanceIfAnyForDebuggerOnly);
- return evaluator.Evaluate();
- }
- }
-
- private void EvaluateChooseElement(ProjectChooseElement chooseElement)
- {
- foreach (ProjectWhenElement element in chooseElement.WhenElements)
- {
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.PulseState(element.Location, this.propertyPassLocals);
- }
- if (this.EvaluateConditionCollectingConditionedProperties(element, ExpanderOptions.ExpandProperties, ParserOptions.AllowProperties))
- {
- this.EvaluateWhenOrOtherwiseChildren(element.Children);
- return;
- }
- }
- if (chooseElement.OtherwiseElement != null)
- {
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.PulseState(chooseElement.OtherwiseElement.Location, this.propertyPassLocals);
- }
- this.EvaluateWhenOrOtherwiseChildren(chooseElement.OtherwiseElement.Children);
- }
- }
-
- private bool EvaluateCondition(ProjectElement element, ExpanderOptions expanderOptions, ParserOptions parserOptions)
- {
- string directoryPath;
- if (element.Condition.Length == 0)
- {
- return true;
- }
- if (((element is ProjectPropertyGroupElement) || (element is ProjectImportElement)) || (element is ProjectImportGroupElement))
- {
- directoryPath = element.ContainingProject.DirectoryPath;
- }
- else
- {
- directoryPath = this.data.Directory;
- }
- return ConditionEvaluator.EvaluateCondition<P, I>(element.Condition, parserOptions, this.expander, expanderOptions, directoryPath, element.ConditionLocation, this.loggingService, this.buildEventContext);
- }
-
- private bool EvaluateConditionCollectingConditionedProperties(ProjectElement element, ExpanderOptions expanderOptions, ParserOptions parserOptions)
- {
- if (element.Condition.Length == 0)
- {
- return true;
- }
- if (!this.data.ShouldEvaluateForDesignTime)
- {
- return this.EvaluateCondition(element, expanderOptions, parserOptions);
- }
- return ConditionEvaluator.EvaluateConditionCollectingConditionedProperties<P, I>(element.Condition, parserOptions, this.expander, expanderOptions, this.data.ConditionedProperties, element.ContainingProject.DirectoryPath, element.ConditionLocation, this.loggingService, this.buildEventContext);
- }
-
- private void EvaluateImportElement(string directoryOfImportingFile, ProjectImportElement importElement)
- {
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.EnterState(importElement.Location, this.propertyPassLocals);
- }
- if (this.EvaluateConditionCollectingConditionedProperties(importElement, ExpanderOptions.ExpandProperties, ParserOptions.AllowProperties))
- {
- string importExpressionEscaped = this.expander.ExpandIntoStringLeaveEscaped(importElement.Project, ExpanderOptions.ExpandProperties, importElement.ProjectLocation);
- foreach (ProjectRootElement element in this.ExpandAndLoadImports(directoryOfImportingFile, importExpressionEscaped, importElement))
- {
- this.data.RecordImport(importElement, element, element.Version);
- if (DebuggerManager.DebuggingEnabled)
- {
- this.importRelationships.Add(element, importElement.ContainingProject);
- }
- this.PerformDepthFirstPass(element);
- }
- }
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.LeaveState(importElement.Location);
- }
- }
-
- private void EvaluateImportGroupElement(string directoryOfImportingFile, ProjectImportGroupElement importGroupElement)
- {
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.PulseState(importGroupElement.Location, this.propertyPassLocals);
- }
- if (this.EvaluateConditionCollectingConditionedProperties(importGroupElement, ExpanderOptions.ExpandProperties, ParserOptions.AllowProperties))
- {
- foreach (ProjectImportElement element in importGroupElement.Imports)
- {
- this.EvaluateImportElement(directoryOfImportingFile, element);
- }
- }
- }
-
- private void EvaluateItemDefinitionElement(ProjectItemDefinitionElement itemDefinitionElement)
- {
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.PulseState(itemDefinitionElement.Location, this.itemDefinitionPassLocals);
- }
- IItemDefinition<M> itemDefinition = this.data.GetItemDefinition(itemDefinitionElement.ItemType);
- if (itemDefinition != null)
- {
- this.expander.Metadata = itemDefinition;
- }
- else
- {
- this.expander.Metadata = new EvaluatorMetadataTable(itemDefinitionElement.ItemType);
- }
- if (this.EvaluateCondition(itemDefinitionElement, ExpanderOptions.ExpandPropertiesAndMetadata, ParserOptions.AllowPropertiesAndCustomMetadata))
- {
- if (itemDefinition == null)
- {
- itemDefinition = this.data.AddItemDefinition(itemDefinitionElement.ItemType);
- this.expander.Metadata = itemDefinition;
- }
- foreach (ProjectMetadataElement element in itemDefinitionElement.Metadata)
- {
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.PulseState(element.Location, this.itemDefinitionPassLocals);
- }
- if (this.EvaluateCondition(element, ExpanderOptions.ExpandPropertiesAndMetadata, ParserOptions.AllowPropertiesAndCustomMetadata))
- {
- string evaluatedValue = this.expander.ExpandIntoStringLeaveEscaped(element.Value, ExpanderOptions.ExpandPropertiesAndCustomMetadata, itemDefinitionElement.Location);
- M metadata = itemDefinition.GetMetadata(element.Name);
- M itemDefinitionMetadatum = itemDefinition.SetMetadata(element, evaluatedValue, metadata);
- if (this.data.ShouldEvaluateForDesignTime)
- {
- this.data.AddToAllEvaluatedItemDefinitionMetadataList(itemDefinitionMetadatum);
- }
- }
- }
- }
- this.expander.Metadata = null;
- }
-
- private void EvaluateItemDefinitionGroupElement(ProjectItemDefinitionGroupElement itemDefinitionGroupElement)
- {
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.PulseState(itemDefinitionGroupElement.Location, this.itemDefinitionPassLocals);
- }
- if (this.EvaluateCondition(itemDefinitionGroupElement, ExpanderOptions.ExpandProperties, ParserOptions.AllowProperties))
- {
- foreach (ProjectItemDefinitionElement element in itemDefinitionGroupElement.ItemDefinitions)
- {
- this.EvaluateItemDefinitionElement(element);
- }
- }
- }
-
- private void EvaluateItemElement(bool itemGroupConditionResult, ProjectItemElement itemElement)
- {
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.EnterState(itemElement.Location, this.itemPassLocals);
- }
- bool flag = this.EvaluateCondition(itemElement, ExpanderOptions.ExpandPropertiesAndItems, ParserOptions.AllowPropertiesAndItemLists);
- if (!flag && !this.data.ShouldEvaluateForDesignTime)
- {
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.LeaveState(itemElement.Location);
- }
- }
- else
- {
- IList<I> destinationItems = Evaluator<P, I, M, D>.CreateItemsFromInclude(this.projectRootElement.DirectoryPath, itemElement, this.itemFactory, itemElement.Include, this.expander);
- if (itemElement.Exclude.Length > 0)
- {
- string expression = this.expander.ExpandIntoStringLeaveEscaped(itemElement.Exclude, ExpanderOptions.ExpandPropertiesAndItems, itemElement.ExcludeLocation);
- if (expression.Length > 0)
- {
- IList<string> list2 = ExpressionShredder.SplitSemiColonSeparatedList(expression);
- HashSet<string> set = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
- foreach (string str2 in list2)
- {
- foreach (string str3 in EngineFileUtilities.GetFileListEscaped(this.projectRootElement.DirectoryPath, str2))
- {
- set.Add(EscapingUtilities.UnescapeAll(str3));
- }
- }
- List<I> list3 = new List<I>();
- for (int i = 0; i < destinationItems.Count; i++)
- {
- I local4 = destinationItems[i];
- if (!set.Contains(local4.EvaluatedInclude))
- {
- list3.Add(destinationItems[i]);
- }
- }
- destinationItems = list3;
- }
- }
- if (itemElement.HasMetadata)
- {
- List<string> expressions = new List<string>(itemElement.Count);
- foreach (ProjectMetadataElement element in itemElement.Metadata)
- {
- expressions.Add(element.Value);
- expressions.Add(element.Condition);
- }
- ItemsAndMetadataPair referencedItemNamesAndMetadata = ExpressionShredder.GetReferencedItemNamesAndMetadata(expressions);
- bool flag2 = false;
- if ((referencedItemNamesAndMetadata.Metadata != null) && (referencedItemNamesAndMetadata.Metadata.Values.Count > 0))
- {
- ItemsAndMetadataPair pair2 = ExpressionShredder.GetReferencedItemNamesAndMetadata(new List<string> { itemElement.Include });
- if ((pair2.Items != null) && (pair2.Items.Count > 0))
- {
- flag2 = true;
- }
- else if (referencedItemNamesAndMetadata.Metadata.Values.Count > 0)
- {
- flag2 = true;
- }
- }
- if (flag2)
- {
- foreach (I local in destinationItems)
- {
- this.expander.Metadata = local;
- foreach (ProjectMetadataElement element2 in itemElement.Metadata)
- {
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.PulseState(element2.Location, this.itemPassLocals);
- }
- if (this.EvaluateCondition(element2, ExpanderOptions.ExpandAll, ParserOptions.AllowAll))
- {
- string evaluatedValue = this.expander.ExpandIntoStringLeaveEscaped(element2.Value, ExpanderOptions.ExpandAll, element2.Location);
- local.SetMetadata(element2, evaluatedValue);
- }
- }
- }
- this.expander.Metadata = null;
- }
- else
- {
- EvaluatorMetadataTable table = new EvaluatorMetadataTable(itemElement.ItemType);
- this.expander.Metadata = table;
- List<Pair<ProjectMetadataElement, string>> metadata = new List<Pair<ProjectMetadataElement, string>>();
- foreach (ProjectMetadataElement element3 in itemElement.Metadata)
- {
- if (this.EvaluateCondition(element3, ExpanderOptions.ExpandAll, ParserOptions.AllowAll))
- {
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.PulseState(element3.Location, this.itemPassLocals);
- }
- string evaluatedValueEscaped = this.expander.ExpandIntoStringLeaveEscaped(element3.Value, ExpanderOptions.ExpandAll, element3.Location);
- table.SetValue(element3, evaluatedValueEscaped);
- metadata.Add(new Pair<ProjectMetadataElement, string>(element3, evaluatedValueEscaped));
- }
- }
- this.itemFactory.SetMetadata(metadata, destinationItems);
- this.expander.Metadata = null;
- }
- }
- if (flag && itemGroupConditionResult)
- {
- foreach (I local2 in destinationItems)
- {
- this.data.AddItem(local2);
- if (this.data.ShouldEvaluateForDesignTime)
- {
- this.data.AddToAllEvaluatedItemsList(local2);
- }
- }
- }
- if (this.data.ShouldEvaluateForDesignTime)
- {
- foreach (I local3 in destinationItems)
- {
- this.data.AddItemIgnoringCondition(local3);
- }
- }
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.LeaveState(itemElement.Location);
- }
- }
- }
-
- private void EvaluateItemGroupElement(ProjectItemGroupElement itemGroupElement)
- {
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.PulseState(itemGroupElement.Location, this.itemPassLocals);
- }
- bool itemGroupConditionResult = this.EvaluateCondition(itemGroupElement, ExpanderOptions.ExpandPropertiesAndItems, ParserOptions.AllowPropertiesAndItemLists);
- if (itemGroupConditionResult || this.data.ShouldEvaluateForDesignTime)
- {
- foreach (ProjectItemElement element in itemGroupElement.Items)
- {
- this.EvaluateItemElement(itemGroupConditionResult, element);
- }
- }
- }
-
- private void EvaluatePropertyElement(ProjectPropertyElement propertyElement)
- {
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.EnterState(propertyElement.Location, this.propertyPassLocals);
- }
- if (this.data.GlobalPropertiesDictionary.ContainsKey(propertyElement.Name))
- {
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.LeaveState(propertyElement.Location);
- }
- }
- else if (!this.EvaluateConditionCollectingConditionedProperties(propertyElement, ExpanderOptions.ExpandProperties, ParserOptions.AllowProperties))
- {
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.LeaveState(propertyElement.Location);
- }
- }
- else
- {
- this.expander.UsedUninitializedProperties.CurrentlyEvaluatingPropertyElementName = propertyElement.Name;
- string evaluatedValueEscaped = this.expander.ExpandIntoStringLeaveEscaped(propertyElement.Value, ExpanderOptions.ExpandProperties, propertyElement.Location);
- if ((evaluatedValueEscaped.Length > 0) && this.expander.WarnForUninitializedProperties)
- {
- IElementLocation location = null;
- if (this.expander.UsedUninitializedProperties.Properties.TryGetValue(propertyElement.Name, out location))
- {
- this.expander.UsedUninitializedProperties.Properties.Remove(propertyElement.Name);
- this.loggingService.LogWarning(this.buildEventContext, null, new BuildEventFileInfo(propertyElement.Location), "UsedUninitializedProperty", new object[] { propertyElement.Name, location.LocationString });
- }
- }
- this.expander.UsedUninitializedProperties.CurrentlyEvaluatingPropertyElementName = null;
- P property = this.data.GetProperty(propertyElement.Name);
- this.data.SetProperty(propertyElement, evaluatedValueEscaped, property);
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.LeaveState(propertyElement.Location);
- }
- }
- }
-
- private void EvaluatePropertyGroupElement(ProjectPropertyGroupElement propertyGroupElement)
- {
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.PulseState(propertyGroupElement.Location, this.propertyPassLocals);
- }
- if (this.EvaluateConditionCollectingConditionedProperties(propertyGroupElement, ExpanderOptions.ExpandProperties, ParserOptions.AllowProperties))
- {
- foreach (ProjectPropertyElement element in propertyGroupElement.Properties)
- {
- this.EvaluatePropertyElement(element);
- }
- }
- }
-
- private void EvaluateUsingTaskElement(string directoryOfImportingFile, ProjectUsingTaskElement projectUsingTaskElement)
- {
- if (DebuggerManager.DebuggingEnabled)
- {
- DebuggerManager.PulseState(projectUsingTaskElement.Location, this.itemPassLocals);
- }
- TaskRegistry.RegisterTasksFromUsingTaskElement<P, I>(this.loggingService, this.buildEventContext, directoryOfImportingFile, projectUsingTaskElement, this.data.TaskRegistry, this.expander, ExpanderOptions.ExpandPropertiesAndItems);
- }
-
- private bool EvaluateWhenOrOtherwiseChildren(IEnumerable<ProjectElement> children)
- {
- foreach (ProjectElement element in children)
- {
- ProjectPropertyGroupElement propertyGroupElement = element as ProjectPropertyGroupElement;
- if (propertyGroupElement != null)
- {
- this.EvaluatePropertyGroupElement(propertyGroupElement);
- }
- else
- {
- ProjectItemGroupElement item = element as ProjectItemGroupElement;
- if (item != null)
- {
- this.itemGroupElements.Add(item);
- continue;
- }
- ProjectChooseElement chooseElement = element as ProjectChooseElement;
- if (chooseElement != null)
- {
- this.EvaluateChooseElement(chooseElement);
- continue;
- }
- ErrorUtilities.ThrowInternalError("Unexpected child type", new object[0]);
- }
- }
- return true;
- }
-
- private List<ProjectRootElement> ExpandAndLoadImports(string directoryOfImportingFile, string importExpressionEscaped, ProjectImportElement importElement)
- {
- IElementLocation elementLocation = importElement.Location;
- List<ProjectRootElement> list = new List<ProjectRootElement>();
- string[] fileListEscaped = null;
- try
- {
- if ((importExpressionEscaped.Length == 0) || (importExpressionEscaped.Trim().Length == 0))
- {
- FileUtilities.NormalizePath(EscapingUtilities.UnescapeAll(importExpressionEscaped));
- }
- fileListEscaped = EngineFileUtilities.GetFileListEscaped(directoryOfImportingFile, importExpressionEscaped);
- }
- catch (Exception exception)
- {
- if (ExceptionHandling.NotExpectedException(exception))
- {
- throw;
- }
- ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidAttributeValueWithException", EscapingUtilities.UnescapeAll(importExpressionEscaped), "Project", "Import", exception.Message);
- }
- foreach (string str in fileListEscaped)
- {
- ProjectRootElementCache.OpenProjectRootElement openProjectRootElement = null;
- string importFileUnescaped = EscapingUtilities.UnescapeAll(str);
- try
- {
- if ((directoryOfImportingFile != null) && !Path.IsPathRooted(importFileUnescaped))
- {
- importFileUnescaped = Path.Combine(directoryOfImportingFile, importFileUnescaped);
- }
- importFileUnescaped = FileUtilities.NormalizePath(importFileUnescaped);
- }
- catch (Exception exception2)
- {
- if (ExceptionHandling.NotExpectedException(exception2))
- {
- throw;
- }
- ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidAttributeValueWithException", importFileUnescaped, "Project", "Import", exception2.Message);
- }
- if (string.Equals(this.projectRootElement.FullPath, importFileUnescaped, StringComparison.OrdinalIgnoreCase))
- {
- this.loggingService.LogWarning(this.buildEventContext, null, new BuildEventFileInfo(elementLocation), "SelfImport", new object[] { importFileUnescaped });
- }
- else if ((((this.loadSettings & ProjectLoadSettings.RejectCircularImports) != ProjectLoadSettings.Default) || ((this.loadSettings & ProjectLoadSettings.RecordDuplicateButNotCircularImports) != ProjectLoadSettings.Default)) && this.IntroducesCircularity(importFileUnescaped, importElement))
- {
- string str2 = importElement.ContainingProject.FullPath ?? string.Empty;
- this.loggingService.LogWarning(this.buildEventContext, null, new BuildEventFileInfo(elementLocation), "ImportIntroducesCircularity", new object[] { importFileUnescaped, str2 });
- if ((this.loadSettings & ProjectLoadSettings.RejectCircularImports) != ProjectLoadSettings.Default)
- {
- ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "ImportIntroducesCircularity", importFileUnescaped, str2);
- }
- }
- else
- {
- ProjectImportElement element;
- bool flag = false;
- if (this.importsSeen.TryGetValue(importFileUnescaped, out element))
- {
- string str3 = string.Empty;
- if ((element.ContainingProject != this.projectRootElement) && (importElement.ContainingProject != this.projectRootElement))
- {
- str3 = "[" + this.projectRootElement.FullPath + "]";
- }
- this.loggingService.LogWarning(this.buildEventContext, null, new BuildEventFileInfo(elementLocation), "DuplicateImport", new object[] { importFileUnescaped, element.Location.LocationString, str3 });
- flag = true;
- }
- try
- {
- if (openProjectRootElement == null)
- {
- openProjectRootElement = () => ProjectRootElement.OpenProjectOrSolution(importFileUnescaped, new ReadOnlyConvertingDictionary<string, ProjectPropertyInstance, string>(((Evaluator<P, I, M, D>) this).data.GlobalPropertiesDictionary, instance => ((IProperty) instance).EvaluatedValueEscaped), ((Evaluator<P, I, M, D>) this).data.ExplicitToolsVersion, ((Evaluator<P, I, M, D>) this).loggingService, ((Evaluator<P, I, M, D>) this).projectRootElementCache, ((Evaluator<P, I, M, D>) this).buildEventContext);
- }
- ProjectRootElement import = this.projectRootElementCache.Get(importFileUnescaped, openProjectRootElement);
- if (flag)
- {
- if ((this.loadSettings & ProjectLoadSettings.RecordDuplicateButNotCircularImports) != ProjectLoadSettings.Default)
- {
- this.data.RecordImportWithDuplicates(importElement, import, import.Version);
- }
- goto Label_0362;
- }
- list.Add(import);
- }
- catch (InvalidProjectFileException exception3)
- {
- if (ExceptionHandling.IsIoRelatedException(exception3.InnerException))
- {
- if (!File.Exists(importFileUnescaped))
- {
- if ((this.loadSettings & ProjectLoadSettings.IgnoreMissingImports) != ProjectLoadSettings.Default)
- {
- goto Label_0362;
- }
- ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "ImportedProjectNotFound", importFileUnescaped);
- }
- else
- {
- ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "InvalidImportedProjectFile", importFileUnescaped, exception3.InnerException.Message);
- …
Large files files are truncated, but you can click here to view the full file