/Microsoft.Build/Microsoft.Build/Microsoft/Build/Evaluation/Project.cs
C# | 1678 lines | 1520 code | 158 blank | 0 comment | 152 complexity | d76c758d4fc87ae599c80bed986a662d 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.Logging;
- using Microsoft.Build.Collections;
- using Microsoft.Build.Construction;
- using Microsoft.Build.Exceptions;
- using Microsoft.Build.Execution;
- using Microsoft.Build.Framework;
- using Microsoft.Build.Internal;
- using Microsoft.Build.Shared;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Runtime;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading;
- using System.Xml;
-
- [DebuggerDisplay("{FullPath} EffectiveToolsVersion={ToolsVersion} #GlobalProperties={data.globalProperties.Count} #Properties={data.Properties.Count} #ItemTypes={data.ItemTypes.Count} #ItemDefinitions={data.ItemDefinitions.Count} #Items={data.Items.Count} #Targets={data.Targets.Count}")]
- public class Project
- {
- private static BuildEventContext buildEventContext = new BuildEventContext(0, -1, -2, -1);
- private Data data;
- private static readonly bool debugEvaluation = (Environment.GetEnvironmentVariable("MSBUILDDEBUGEVALUATION") != null);
- private int evaluatedToolsetCollectionVersion;
- private int evaluatedVersion;
- private int evaluationCounter;
- private bool explicitlyMarkedDirty;
- private BuildEnabledSetting isBuildEnabled;
- private ProjectLoadSettings loadSettings;
- private readonly Microsoft.Build.Evaluation.ProjectCollection projectCollection;
- private RenameHandlerDelegate renameHandler;
- private readonly ProjectRootElement xml;
-
- public Project() : this(ProjectRootElement.Create(Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection))
- {
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public Project(ProjectRootElement xml) : this(xml, null, null)
- {
- }
-
- public Project(Microsoft.Build.Evaluation.ProjectCollection projectCollection) : this(ProjectRootElement.Create(projectCollection), null, null, projectCollection)
- {
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public Project(string projectFile) : this(projectFile, null, null)
- {
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public Project(XmlReader xmlReader) : this(xmlReader, null, null)
- {
- }
-
- public Project(IDictionary<string, string> globalProperties, string toolsVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection) : this(ProjectRootElement.Create(projectCollection), globalProperties, toolsVersion, projectCollection)
- {
- }
-
- public Project(ProjectRootElement xml, IDictionary<string, string> globalProperties, string toolsVersion) : this(xml, globalProperties, toolsVersion, Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection)
- {
- }
-
- public Project(string projectFile, IDictionary<string, string> globalProperties, string toolsVersion) : this(projectFile, globalProperties, toolsVersion, Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection)
- {
- }
-
- public Project(XmlReader xmlReader, IDictionary<string, string> globalProperties, string toolsVersion) : this(xmlReader, globalProperties, toolsVersion, Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection)
- {
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public Project(ProjectRootElement xml, IDictionary<string, string> globalProperties, string toolsVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection) : this(xml, globalProperties, toolsVersion, projectCollection, ProjectLoadSettings.Default)
- {
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public Project(string projectFile, IDictionary<string, string> globalProperties, string toolsVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection) : this(projectFile, globalProperties, toolsVersion, projectCollection, ProjectLoadSettings.Default)
- {
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public Project(XmlReader xmlReader, IDictionary<string, string> globalProperties, string toolsVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection) : this(xmlReader, globalProperties, toolsVersion, projectCollection, ProjectLoadSettings.Default)
- {
- }
-
- public Project(ProjectRootElement xml, IDictionary<string, string> globalProperties, string toolsVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection, ProjectLoadSettings loadSettings)
- {
- this.projectCollection = Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection;
- this.isBuildEnabled = BuildEnabledSetting.UseProjectCollectionSetting;
- ErrorUtilities.VerifyThrowArgumentNull(xml, "xml");
- ErrorUtilities.VerifyThrowArgumentLengthIfNotNull(toolsVersion, "toolsVersion");
- ErrorUtilities.VerifyThrowArgumentNull(projectCollection, "projectCollection");
- this.xml = xml;
- this.projectCollection = projectCollection;
- this.Initialize(globalProperties, toolsVersion, loadSettings);
- }
-
- public Project(string projectFile, IDictionary<string, string> globalProperties, string toolsVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection, ProjectLoadSettings loadSettings)
- {
- this.projectCollection = Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection;
- this.isBuildEnabled = BuildEnabledSetting.UseProjectCollectionSetting;
- ErrorUtilities.VerifyThrowArgumentNull(projectFile, "projectFile");
- ErrorUtilities.VerifyThrowArgumentLengthIfNotNull(toolsVersion, "toolsVersion");
- ErrorUtilities.VerifyThrowArgumentNull(projectCollection, "projectCollection");
- this.projectCollection = projectCollection;
- projectFile = FileUtilities.NormalizePath(projectFile);
- try
- {
- this.xml = ProjectRootElement.OpenProjectOrSolution(projectFile, globalProperties, toolsVersion, this.LoggingService, projectCollection.ProjectRootElementCache, buildEventContext);
- }
- catch (InvalidProjectFileException exception)
- {
- this.LoggingService.LogInvalidProjectFileError(buildEventContext, exception);
- throw;
- }
- try
- {
- this.Initialize(globalProperties, toolsVersion, loadSettings);
- }
- catch (Exception exception2)
- {
- if (!ExceptionHandling.IsCriticalException(exception2))
- {
- projectCollection.TryUnloadProject(this.xml);
- }
- throw;
- }
- }
-
- public Project(XmlReader xmlReader, IDictionary<string, string> globalProperties, string toolsVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection, ProjectLoadSettings loadSettings)
- {
- this.projectCollection = Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection;
- this.isBuildEnabled = BuildEnabledSetting.UseProjectCollectionSetting;
- ErrorUtilities.VerifyThrowArgumentNull(xmlReader, "xmlReader");
- ErrorUtilities.VerifyThrowArgumentLengthIfNotNull(toolsVersion, "toolsVersion");
- ErrorUtilities.VerifyThrowArgumentNull(projectCollection, "projectCollection");
- this.projectCollection = projectCollection;
- try
- {
- this.xml = ProjectRootElement.Create(xmlReader, projectCollection);
- }
- catch (InvalidProjectFileException exception)
- {
- this.LoggingService.LogInvalidProjectFileError(buildEventContext, exception);
- throw;
- }
- this.Initialize(globalProperties, toolsVersion, loadSettings);
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public IList<ProjectItem> AddItem(string itemType, string unevaluatedInclude)
- {
- return this.AddItem(itemType, unevaluatedInclude, null);
- }
-
- public IList<ProjectItem> AddItem(string itemType, string unevaluatedInclude, IEnumerable<KeyValuePair<string, string>> metadata)
- {
- ProjectItemElement element;
- ProjectElement element2 = this.GetAnySuitableExistingItemXml(itemType, unevaluatedInclude, metadata, out element);
- if (element == null)
- {
- ProjectItemElement reference = element2 as ProjectItemElement;
- if (reference != null)
- {
- element = this.xml.CreateItemElement(itemType, unevaluatedInclude);
- reference.Parent.InsertBeforeChild(element, reference);
- }
- else
- {
- ProjectItemGroupElement element4 = element2 as ProjectItemGroupElement;
- if (element4 != null)
- {
- element = element4.AddItem(itemType, unevaluatedInclude);
- }
- else
- {
- element = this.xml.AddItem(itemType, unevaluatedInclude);
- }
- }
- }
- return this.AddItemHelper(element, unevaluatedInclude, metadata);
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public IList<ProjectItem> AddItemFast(string itemType, string unevaluatedInclude)
- {
- return this.AddItemFast(itemType, unevaluatedInclude, null);
- }
-
- public IList<ProjectItem> AddItemFast(string itemType, string unevaluatedInclude, IEnumerable<KeyValuePair<string, string>> metadata)
- {
- ProjectItemElement element3;
- ErrorUtilities.VerifyThrowArgumentLength(itemType, "itemType");
- ErrorUtilities.VerifyThrowArgumentLength(unevaluatedInclude, "unevalutedInclude");
- ProjectItemGroupElement element = null;
- foreach (ProjectItemGroupElement element2 in this.xml.ItemGroups)
- {
- if ((element2.Condition.Length <= 0) && ((element2.Count == 0) || MSBuildNameIgnoreCaseComparer.Default.Equals(itemType, element2.Items.First<ProjectItemElement>().ItemType)))
- {
- element = element2;
- break;
- }
- }
- if (element == null)
- {
- element = this.xml.AddItemGroup();
- }
- if (((element.Count == 0) || FileMatcher.HasWildcardsSemicolonItemOrPropertyReferences(unevaluatedInclude)) || !this.IsSuitableExistingItemXml(element.Items.First<ProjectItemElement>(), unevaluatedInclude, metadata))
- {
- element3 = this.xml.CreateItemElement(itemType, unevaluatedInclude);
- element.AppendChild(element3);
- }
- else
- {
- element3 = element.Items.First<ProjectItemElement>();
- }
- return this.AddItemHelper(element3, unevaluatedInclude, metadata);
- }
-
- private List<ProjectItem> AddItemHelper(ProjectItemElement itemElement, string unevaluatedInclude, IEnumerable<KeyValuePair<string, string>> metadata)
- {
- ProjectItem.ProjectItemFactory itemFactory = new ProjectItem.ProjectItemFactory(this, itemElement);
- List<ProjectItem> list = Evaluator<ProjectProperty, ProjectItem, ProjectMetadata, ProjectItemDefinition>.CreateItemsFromInclude(this.DirectoryPath, itemElement, itemFactory, unevaluatedInclude, this.data.Expander);
- foreach (ProjectItem item in list)
- {
- this.data.AddItem(item);
- this.data.AddItemIgnoringCondition(item);
- }
- if (metadata != null)
- {
- foreach (ProjectItem item2 in list)
- {
- foreach (KeyValuePair<string, string> pair in metadata)
- {
- item2.SetMetadataValue(pair.Key, pair.Value);
- }
- }
- }
- return list;
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public bool Build()
- {
- return this.Build((string[]) null);
- }
-
- public bool Build(ILogger logger)
- {
- List<ILogger> loggers = new List<ILogger>(1) {
- logger
- };
- return this.Build((string[]) null, loggers, null);
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public bool Build(string[] targets)
- {
- return this.Build(targets, null, null);
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public bool Build(IEnumerable<ILogger> loggers)
- {
- return this.Build((string[]) null, loggers, null);
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public bool Build(string target)
- {
- return this.Build(target, null, null);
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public bool Build(string target, IEnumerable<ILogger> loggers)
- {
- return this.Build(target, loggers, null);
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public bool Build(string[] targets, IEnumerable<ILogger> loggers)
- {
- return this.Build(targets, loggers, null);
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public bool Build(IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers)
- {
- return this.Build((string[]) null, loggers, remoteLoggers);
- }
-
- public bool Build(string[] targets, IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers)
- {
- IDictionary<string, TargetResult> dictionary;
- if (!this.IsBuildEnabled)
- {
- this.LoggingService.LogError(buildEventContext, new BuildEventFileInfo(this.FullPath), "SecurityProjectBuildDisabled", new object[0]);
- return false;
- }
- ProjectInstance instance = this.CreateProjectInstance(this.LoggingService);
- if ((loggers == null) && (this.ProjectCollection.Loggers != null))
- {
- loggers = this.ProjectCollection.Loggers;
- }
- return instance.Build(targets, loggers, remoteLoggers, null, out dictionary);
- }
-
- public bool Build(string target, IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers)
- {
- string[] targets = (target == null) ? null : new string[] { target };
- return this.Build(targets, loggers, remoteLoggers);
- }
-
- public ProjectInstance CreateProjectInstance()
- {
- return this.CreateProjectInstance(this.LoggingService);
- }
-
- private ProjectInstance CreateProjectInstance(ILoggingService loggingServiceForEvaluation)
- {
- this.ReevaluateIfNecessary(loggingServiceForEvaluation);
- return new ProjectInstance(this.data, this.DirectoryPath, this.FullPath, this.ProjectCollection.HostServices, this.projectCollection.EnvironmentProperties);
- }
-
- internal string ExpandItemIncludeBestEffortLeaveEscaped(ProjectItemElement renamedItemElement)
- {
- if (renamedItemElement.Exclude.Length > 0)
- {
- return renamedItemElement.Include;
- }
- ProjectItem.ProjectItemFactory itemFactory = new ProjectItem.ProjectItemFactory(this, renamedItemElement);
- List<ProjectItem> list = Evaluator<ProjectProperty, ProjectItem, ProjectMetadata, ProjectItemDefinition>.CreateItemsFromInclude(this.DirectoryPath, renamedItemElement, itemFactory, renamedItemElement.Include, this.data.Expander);
- if (list.Count != 1)
- {
- return renamedItemElement.Include;
- }
- return list[0].EvaluatedIncludeEscaped;
- }
-
- internal string ExpandMetadataValueBestEffortLeaveEscaped(IMetadataTable metadataTable, string unevaluatedValue, IElementLocation metadataLocation)
- {
- ErrorUtilities.VerifyThrow(this.data.Expander.Metadata == null, "Should be null");
- this.data.Expander.Metadata = metadataTable;
- string str = this.data.Expander.ExpandIntoStringLeaveEscaped(unevaluatedValue, ExpanderOptions.ExpandAll, metadataLocation);
- this.data.Expander.Metadata = null;
- return str;
- }
-
- internal string ExpandPropertyValueBestEffortLeaveEscaped(string unevaluatedValue, IElementLocation propertyLocation)
- {
- return this.data.Expander.ExpandIntoStringLeaveEscaped(unevaluatedValue, ExpanderOptions.ExpandProperties, propertyLocation);
- }
-
- public string ExpandString(string unexpandedValue)
- {
- ErrorUtilities.VerifyThrowArgumentNull(unexpandedValue, "unexpandedValue");
- return this.data.Expander.ExpandIntoStringAndUnescape(unexpandedValue, ExpanderOptions.ExpandPropertiesAndItems, this.ProjectFileLocation);
- }
-
- private ProjectElement GetAnySuitableExistingItemXml(string itemType, string unevaluatedInclude, IEnumerable<KeyValuePair<string, string>> metadata, out ProjectItemElement suitableExistingItemXml)
- {
- suitableExistingItemXml = null;
- if (FileMatcher.HasWildcardsSemicolonItemOrPropertyReferences(unevaluatedInclude))
- {
- return null;
- }
- if ((metadata != null) && metadata.Any<KeyValuePair<string, string>>())
- {
- return null;
- }
- ProjectItemGroupElement element = null;
- ProjectItemElement element2 = null;
- foreach (ProjectItemGroupElement element3 in this.xml.ItemGroups)
- {
- if ((element3.Condition.Length <= 0) && !element3.DefinitelyAreNoChildrenWithWildcards)
- {
- if ((element == null) && (element3.Count == 0))
- {
- element = element3;
- }
- foreach (ProjectItemElement element4 in element3.Items)
- {
- if (!MSBuildNameIgnoreCaseComparer.Default.Equals(itemType, element4.ItemType))
- {
- continue;
- }
- if ((element == null) || (element.Count == 0))
- {
- element = element3;
- }
- if ((element2 == null) && (string.Compare(unevaluatedInclude, element4.Include, StringComparison.OrdinalIgnoreCase) < 0))
- {
- element2 = element4;
- }
- if (this.IsSuitableExistingItemXml(element4, unevaluatedInclude, metadata))
- {
- suitableExistingItemXml = element4;
- return null;
- }
- }
- continue;
- }
- }
- if (element2 == null)
- {
- return element;
- }
- return element2;
- }
-
- public static string GetEvaluatedItemIncludeEscaped(ProjectItem item)
- {
- ErrorUtilities.VerifyThrowArgumentNull(item, "item");
- return ((IItem) item).EvaluatedIncludeEscaped;
- }
-
- public static string GetEvaluatedItemIncludeEscaped(ProjectItemDefinition item)
- {
- ErrorUtilities.VerifyThrowArgumentNull(item, "item");
- return ((IItem) item).EvaluatedIncludeEscaped;
- }
-
- public ICollection<ProjectItem> GetItems(string itemType)
- {
- return this.data.GetItems(itemType);
- }
-
- public ICollection<ProjectItem> GetItemsByEvaluatedInclude(string evaluatedInclude)
- {
- return this.data.GetItemsByEvaluatedInclude(evaluatedInclude);
- }
-
- public ICollection<ProjectItem> GetItemsIgnoringCondition(string itemType)
- {
- return this.data.ItemsIgnoringCondition[itemType];
- }
-
- public IEnumerable<ProjectElement> GetLogicalProject()
- {
- return this.GetLogicalProject(this.Xml.AllChildren);
- }
-
- private IEnumerable<ProjectElement> GetLogicalProject(IEnumerable<ProjectElement> projectElements)
- {
- foreach (ProjectElement iteratorVariable0 in projectElements)
- {
- Func<Triple<ProjectImportElement, ProjectRootElement, int>, bool> predicate = null;
- ProjectImportElement import = iteratorVariable0 as ProjectImportElement;
- if (import == null)
- {
- yield return iteratorVariable0;
- }
- else
- {
- if (predicate == null)
- {
- predicate = triple => object.ReferenceEquals(triple.First, import);
- }
- IEnumerable<ProjectRootElement> iteratorVariable1 = from triple in this.data.ImportClosure.Where<Triple<ProjectImportElement, ProjectRootElement, int>>(predicate) select triple.Second;
- foreach (ProjectRootElement iteratorVariable2 in iteratorVariable1)
- {
- if (iteratorVariable2 != null)
- {
- IEnumerable<ProjectElement> logicalProject = this.GetLogicalProject(iteratorVariable2.AllChildren);
- foreach (ProjectElement iteratorVariable4 in logicalProject)
- {
- yield return iteratorVariable4;
- }
- }
- }
- }
- }
- }
-
- public static string GetMetadataValueEscaped(ProjectMetadata metadatum)
- {
- ErrorUtilities.VerifyThrowArgumentNull(metadatum, "metadatum");
- return metadatum.EvaluatedValueEscaped;
- }
-
- public static string GetMetadataValueEscaped(ProjectItem item, string name)
- {
- ErrorUtilities.VerifyThrowArgumentNull(item, "item");
- return ((IItem) item).GetMetadataValueEscaped(name);
- }
-
- public static string GetMetadataValueEscaped(ProjectItemDefinition item, string name)
- {
- ErrorUtilities.VerifyThrowArgumentNull(item, "item");
- return ((IItem) item).GetMetadataValueEscaped(name);
- }
-
- [DebuggerStepThrough]
- public ProjectProperty GetProperty(string name)
- {
- return this.data.Properties[name];
- }
-
- public string GetPropertyValue(string name)
- {
- return this.data.GetPropertyValue(name);
- }
-
- public static string GetPropertyValueEscaped(ProjectProperty property)
- {
- ErrorUtilities.VerifyThrowArgumentNull(property, "property");
- return ((IProperty) property).EvaluatedValueEscaped;
- }
-
- private void Initialize(IDictionary<string, string> globalProperties, string toolsVersion, ProjectLoadSettings loadSettings)
- {
- PropertyDictionary<ProjectPropertyInstance> dictionary = new PropertyDictionary<ProjectPropertyInstance>();
- foreach (ProjectPropertyInstance instance in this.ProjectCollection.GlobalPropertiesCollection)
- {
- ProjectPropertyInstance projectProperty = instance.DeepClone();
- dictionary.Set(projectProperty);
- }
- if (globalProperties != null)
- {
- foreach (KeyValuePair<string, string> pair in globalProperties)
- {
- dictionary.Set(new ProjectPropertyInstance(pair.Key, pair.Value));
- }
- }
- this.data = new Data(this, dictionary, toolsVersion);
- this.loadSettings = loadSettings;
- this.ReevaluateIfNecessary();
- this.renameHandler = delegate (string oldFullPath) {
- this.projectCollection.OnAfterRenameLoadedProject(oldFullPath, this);
- };
- this.xml.OnAfterProjectRename += this.renameHandler;
- this.renameHandler(null);
- }
-
- internal bool IsSuitableExistingItemXml(ProjectItemElement candidateExistingItemXml, string unevaluatedInclude, IEnumerable<KeyValuePair<string, string>> metadata)
- {
- if (((candidateExistingItemXml.Condition.Length == 0) && (candidateExistingItemXml.Exclude.Length == 0)) && candidateExistingItemXml.IncludeHasWildcards)
- {
- if (((metadata != null) && metadata.Any<KeyValuePair<string, string>>()) || (candidateExistingItemXml.Count > 0))
- {
- return false;
- }
- foreach (string str2 in this.data.Expander.ExpandIntoStringLeaveEscaped(candidateExistingItemXml.Include, ExpanderOptions.ExpandProperties, candidateExistingItemXml.IncludeLocation).Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
- {
- if (FileMatcher.HasWildcards(str2))
- {
- FileMatcher.Result result = FileMatcher.FileMatch(str2, unevaluatedInclude);
- if (result.isLegalFileSpec && result.isMatch)
- {
- return true;
- }
- }
- }
- }
- return false;
- }
-
- public void MarkDirty()
- {
- if (!this.DisableMarkDirty && !this.projectCollection.DisableMarkDirty)
- {
- this.explicitlyMarkedDirty = true;
- }
- }
-
- internal void ReAddExistingItemAfterItemTypeChange(ProjectItem item)
- {
- this.data.AddItem(item);
- this.data.AddItemIgnoringCondition(item);
- }
-
- public void ReevaluateIfNecessary()
- {
- this.ReevaluateIfNecessary(this.LoggingService);
- }
-
- private void ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation)
- {
- if ((!this.SkipEvaluation && !this.projectCollection.SkipEvaluation) && this.IsDirty)
- {
- try
- {
- Evaluator<ProjectProperty, ProjectItem, ProjectMetadata, ProjectItemDefinition>.Evaluate(this.data, this.xml, this.loadSettings, this.ProjectCollection.MaxNodeCount, this.ProjectCollection.EnvironmentProperties, loggingServiceForEvaluation, new ProjectItem.ProjectItemFactory(this), this.projectCollection, this.projectCollection.ProjectRootElementCache, buildEventContext, null);
- int version = this.Xml.Version;
- if (this.data.ImportClosure != null)
- {
- foreach (Triple<ProjectImportElement, ProjectRootElement, int> triple in this.data.ImportClosure)
- {
- version = (version < triple.Third) ? triple.Third : version;
- }
- }
- this.explicitlyMarkedDirty = false;
- this.evaluatedVersion = version;
- this.evaluatedToolsetCollectionVersion = this.ProjectCollection.ToolsetsVersion;
- this.evaluationCounter++;
- this.data.HasUnsavedChanges = false;
- ErrorUtilities.VerifyThrow(!this.IsDirty, "Should not be dirty now");
- }
- catch (InvalidProjectFileException exception)
- {
- loggingServiceForEvaluation.LogInvalidProjectFileError(buildEventContext, exception);
- throw;
- }
- }
- }
-
- public bool RemoveGlobalProperty(string name)
- {
- ErrorUtilities.VerifyThrowArgumentLength(name, "name");
- bool flag = this.data.GlobalPropertiesDictionary.Remove(name);
- if (flag)
- {
- this.ProjectCollection.AfterUpdateLoadedProjectGlobalProperties(this);
- this.MarkDirty();
- bool debugEvaluation = Project.debugEvaluation;
- }
- return flag;
- }
-
- public bool RemoveItem(ProjectItem item)
- {
- ErrorUtilities.VerifyThrowArgumentNull(item, "item");
- ErrorUtilities.VerifyThrowArgument(item.Project == this, "OM_IncorrectObjectAssociation", "ProjectItem", "Project");
- return this.RemoveItemHelper(item);
- }
-
- internal void RemoveItemBeforeItemTypeChange(ProjectItem item)
- {
- this.data.RemoveItem(item);
- }
-
- private bool RemoveItemHelper(ProjectItem item)
- {
- ErrorUtilities.VerifyThrowArgumentNull(item, "item");
- if ((item.Project == null) || (item.Xml.Parent == null))
- {
- return false;
- }
- ErrorUtilities.VerifyThrowArgument(item.Project == this, "OM_IncorrectObjectAssociation", "ProjectItem", "Project");
- this.VerifyThrowInvalidOperationNotImported(item.Xml.ContainingProject);
- this.SplitItemElementIfNecessary(item.Xml);
- ProjectElementContainer parent = item.Xml.Parent;
- item.Xml.Parent.RemoveChild(item.Xml);
- if (parent.Count == 0)
- {
- parent.Parent.RemoveChild(parent);
- }
- return this.data.RemoveItem(item);
- }
-
- public void RemoveItems(IEnumerable<ProjectItem> items)
- {
- ErrorUtilities.VerifyThrowArgumentNull(items, "items");
- List<ProjectItem> list = new List<ProjectItem>(items);
- foreach (ProjectItem item in list)
- {
- this.RemoveItemHelper(item);
- }
- }
-
- public bool RemoveProperty(ProjectProperty property)
- {
- ErrorUtilities.VerifyThrowArgumentNull(property, "property");
- ErrorUtilities.VerifyThrowInvalidOperation(!property.IsReservedProperty, "OM_ReservedName", property.Name);
- ErrorUtilities.VerifyThrowInvalidOperation(!property.IsGlobalProperty, "OM_GlobalProperty", property.Name);
- ErrorUtilities.VerifyThrowArgument(property.Xml.Parent != null, "OM_IncorrectObjectAssociation", "ProjectProperty", "Project");
- this.VerifyThrowInvalidOperationNotImported(property.Xml.ContainingProject);
- ProjectElementContainer parent = property.Xml.Parent;
- property.Xml.Parent.RemoveChild(property.Xml);
- if (parent.Count == 0)
- {
- parent.Parent.RemoveChild(parent);
- }
- return this.data.Properties.Remove(property.Name);
- }
-
- public void Save()
- {
- this.Xml.Save();
- }
-
- public void Save(TextWriter writer)
- {
- this.Xml.Save(writer);
- }
-
- public void Save(string path)
- {
- this.Xml.Save(path);
- }
-
- public void Save(Encoding encoding)
- {
- this.Xml.Save(encoding);
- }
-
- public void Save(string path, Encoding encoding)
- {
- this.Xml.Save(path, encoding);
- }
-
- public void SaveLogicalProject(TextWriter writer)
- {
- XmlDocument preprocessedDocument = Preprocessor.GetPreprocessedDocument(this);
- using (ProjectWriter writer2 = new ProjectWriter(writer))
- {
- writer2.Initialize(preprocessedDocument);
- preprocessedDocument.Save(writer2);
- }
- }
-
- public bool SetGlobalProperty(string name, string escapedValue)
- {
- ProjectPropertyInstance instance = this.data.GlobalPropertiesDictionary[name];
- if ((instance != null) && !(((IProperty) instance).EvaluatedValueEscaped != escapedValue))
- {
- return false;
- }
- string str = (instance == null) ? string.Empty : ((IProperty) instance).EvaluatedValueEscaped;
- this.data.GlobalPropertiesDictionary.Set(new ProjectPropertyInstance(name, escapedValue));
- this.data.Properties.Set(new ProjectProperty(this, name, escapedValue, true, false));
- this.ProjectCollection.AfterUpdateLoadedProjectGlobalProperties(this);
- this.MarkDirty();
- if (debugEvaluation)
- {
- string text1 = escapedValue.Substring(0, Math.Min(escapedValue.Length, 0x4b)) + ((escapedValue.Length > 0x4b) ? "..." : string.Empty);
- if (instance != null)
- {
- string text2 = str.Substring(0, Math.Min(str.Length, 0x4b)) + ((str.Length > 0x4b) ? "..." : string.Empty);
- }
- }
- return true;
- }
-
- public ProjectProperty SetProperty(string name, string unevaluatedValue)
- {
- ErrorUtilities.VerifyThrowArgumentLength(name, "name");
- ErrorUtilities.VerifyThrowArgumentNull(unevaluatedValue, "unevaluatedValue");
- ProjectProperty property = this.data.Properties[name];
- ErrorUtilities.VerifyThrowInvalidOperation((property == null) || !property.IsReservedProperty, "OM_ReservedName", name);
- ErrorUtilities.VerifyThrowInvalidOperation((property == null) || !property.IsGlobalProperty, "OM_GlobalProperty", name);
- if ((((property != null) && !property.IsEnvironmentProperty) && ((property.Xml.Parent != null) && (property.Xml.Parent.Parent != null))) && object.ReferenceEquals(property.Xml.ContainingProject, this.xml))
- {
- property.UnevaluatedValue = unevaluatedValue;
- }
- else
- {
- ProjectPropertyElement xml = this.xml.AddProperty(name, unevaluatedValue);
- property = new ProjectProperty(this, xml, unevaluatedValue, null);
- this.data.Properties[name] = property;
- }
- property.UpdateEvaluatedValue(this.ExpandPropertyValueBestEffortLeaveEscaped(unevaluatedValue, property.Xml.Location));
- return property;
- }
-
- internal bool SplitItemElementIfNecessary(ProjectItemElement itemElement)
- {
- if (!FileMatcher.HasWildcardsSemicolonItemOrPropertyReferences(itemElement.Include))
- {
- return false;
- }
- List<ProjectItem> list = new List<ProjectItem>();
- foreach (ProjectItem item in this.Items)
- {
- if (item.Xml == itemElement)
- {
- list.Add(item);
- }
- }
- if (list.Count <= 1)
- {
- return false;
- }
- foreach (ProjectItem item2 in list)
- {
- item2.SplitOwnItemElement();
- }
- itemElement.Parent.RemoveChild(itemElement);
- return true;
- }
-
- internal bool UsesProjectRootElement(ProjectRootElement xmlRootElement)
- {
- return (object.ReferenceEquals(this.Xml, xmlRootElement) || this.data.ImportClosure.Any<Triple<ProjectImportElement, ProjectRootElement, int>>(triple => object.ReferenceEquals(triple.Second, xmlRootElement)));
- }
-
- internal void VerifyThrowInvalidOperationNotImported(ProjectRootElement otherXml)
- {
- ErrorUtilities.VerifyThrowInvalidOperation(object.ReferenceEquals(this.Xml, otherXml), "OM_CannotModifyEvaluatedObjectInImportedFile", otherXml.Location.File);
- }
-
- internal void VerifyThrowInvalidOperationNotZombie()
- {
- ErrorUtilities.VerifyThrow(this.renameHandler != null, "OM_ProjectIsNoLongerActive");
- }
-
- internal void Zombify()
- {
- this.xml.OnAfterProjectRename -= this.renameHandler;
- this.renameHandler = null;
- }
-
- public ICollection<ProjectMetadata> AllEvaluatedItemDefinitionMetadata
- {
- get
- {
- ICollection<ProjectMetadata> allEvaluatedItemDefinitionMetadata = this.data.AllEvaluatedItemDefinitionMetadata;
- if (allEvaluatedItemDefinitionMetadata == null)
- {
- return ReadOnlyEmptyCollection<ProjectMetadata>.Instance;
- }
- return new ReadOnlyCollection<ProjectMetadata>(allEvaluatedItemDefinitionMetadata);
- }
- }
-
- public ICollection<ProjectItem> AllEvaluatedItems
- {
- get
- {
- ICollection<ProjectItem> allEvaluatedItems = this.data.AllEvaluatedItems;
- if (allEvaluatedItems == null)
- {
- return ReadOnlyEmptyCollection<ProjectItem>.Instance;
- }
- return new ReadOnlyCollection<ProjectItem>(allEvaluatedItems);
- }
- }
-
- public ICollection<ProjectProperty> AllEvaluatedProperties
- {
- get
- {
- ICollection<ProjectProperty> allEvaluatedProperties = this.data.AllEvaluatedProperties;
- if (allEvaluatedProperties == null)
- {
- return ReadOnlyEmptyCollection<ProjectProperty>.Instance;
- }
- return new ReadOnlyCollection<ProjectProperty>(allEvaluatedProperties);
- }
- }
-
- public IDictionary<string, List<string>> ConditionedProperties
- {
- [DebuggerStepThrough]
- get
- {
- return ReadOnlyDictionary<string, List<string>>.CreateWrapper(this.data.ConditionedProperties);
- }
- }
-
- public string DirectoryPath
- {
- [DebuggerStepThrough]
- get
- {
- return this.Xml.DirectoryPath;
- }
- }
-
- public bool DisableMarkDirty
- {
- [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.<DisableMarkDirty>k__BackingField;
- }
- [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- set
- {
- this.<DisableMarkDirty>k__BackingField = value;
- }
- }
-
- public int EvaluationCounter
- {
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.evaluationCounter;
- }
- }
-
- public string FullPath
- {
- [DebuggerStepThrough]
- get
- {
- return this.Xml.FullPath;
- }
- [DebuggerStepThrough]
- set
- {
- this.Xml.FullPath = value;
- }
- }
-
- public IDictionary<string, string> GlobalProperties
- {
- [DebuggerStepThrough]
- get
- {
- if (this.data.GlobalPropertiesDictionary.Count == 0)
- {
- return ReadOnlyEmptyDictionary<string, string>.Instance;
- }
- Dictionary<string, string> backing = new Dictionary<string, string>(this.data.GlobalPropertiesDictionary.Count, MSBuildNameIgnoreCaseComparer.Default);
- foreach (ProjectPropertyInstance instance in this.data.GlobalPropertiesDictionary)
- {
- backing[instance.Name] = ((IProperty) instance).EvaluatedValueEscaped;
- }
- return ReadOnlyDictionary<string, string>.CreateWrapper(backing);
- }
- }
-
- public IList<ResolvedImport> Imports
- {
- get
- {
- List<ResolvedImport> list = new List<ResolvedImport>(this.data.ImportClosure.Count - 1);
- foreach (Triple<ProjectImportElement, ProjectRootElement, int> triple in this.data.ImportClosure)
- {
- if (triple.First != null)
- {
- list.Add(new ResolvedImport(triple.First, triple.Second));
- }
- }
- return list;
- }
- }
-
- public IList<ResolvedImport> ImportsIncludingDuplicates
- {
- get
- {
- ErrorUtilities.VerifyThrowInvalidOperation((this.loadSettings & ProjectLoadSettings.RecordDuplicateButNotCircularImports) != ProjectLoadSettings.Default, "OM_MustSetRecordDuplicateInputs");
- List<ResolvedImport> list = new List<ResolvedImport>(this.data.ImportClosureWithDuplicates.Count - 1);
- foreach (Triple<ProjectImportElement, ProjectRootElement, int> triple in this.data.ImportClosureWithDuplicates)
- {
- if (triple.First != null)
- {
- list.Add(new ResolvedImport(triple.First, triple.Second));
- }
- }
- return list;
- }
- }
-
- public bool IsBuildEnabled
- {
- get
- {
- switch (this.isBuildEnabled)
- {
- case BuildEnabledSetting.BuildEnabled:
- return true;
-
- case BuildEnabledSetting.BuildDisabled:
- return false;
-
- case BuildEnabledSetting.UseProjectCollectionSetting:
- return this.ProjectCollection.IsBuildEnabled;
- }
- ErrorUtilities.ThrowInternalErrorUnreachable();
- return false;
- }
- set
- {
- this.isBuildEnabled = value ? BuildEnabledSetting.BuildEnabled : BuildEnabledSetting.BuildDisabled;
- }
- }
-
- public bool IsDirty
- {
- get
- {
- if (this.explicitlyMarkedDirty)
- {
- bool debugEvaluation = Project.debugEvaluation;
- return true;
- }
- if (this.evaluatedVersion < this.xml.Version)
- {
- if (Project.debugEvaluation)
- {
- int count = this.xml.Count;
- }
- return true;
- }
- if (this.evaluatedToolsetCollectionVersion != this.ProjectCollection.ToolsetsVersion)
- {
- bool flag2 = Project.debugEvaluation;
- return true;
- }
- foreach (Triple<ProjectImportElement, ProjectRootElement, int> triple in this.data.ImportClosure)
- {
- if ((triple.Second.Version != triple.Third) || (this.evaluatedVersion < triple.Third))
- {
- if (Project.debugEvaluation)
- {
- string lastDirtyReason = triple.Second.LastDirtyReason;
- }
- return true;
- }
- }
- return false;
- }
- }
-
- public IDictionary<string, ProjectItemDefinition> ItemDefinitions
- {
- [DebuggerStepThrough]
- get
- {
- return this.data.ItemDefinitions;
- }
- }
-
- public ICollection<ProjectItem> Items
- {
- [DebuggerStepThrough]
- get
- {
- return new ReadOnlyCollection<ProjectItem>(this.data.Items);
- }
- }
-
- public ICollection<ProjectItem> ItemsIgnoringCondition
- {
- [DebuggerStepThrough]
- get
- {
- return new ReadOnlyCollection<ProjectItem>(this.data.ItemsIgnoringCondition);
- }
- }
-
- public ICollection<string> ItemTypes
- {
- [DebuggerStepThrough]
- get
- {
- return this.data.ItemTypes;
- }
- }
-
- internal ILoggingService LoggingService
- {
- [DebuggerStepThrough]
- get
- {
- return this.ProjectCollection.LoggingService;
- }
- }
-
- public Microsoft.Build.Evaluation.ProjectCollection ProjectCollection
- {
- [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.projectCollection;
- }
- }
-
- internal IElementLocation ProjectFileLocation
- {
- get
- {
- return this.xml.ProjectFileLocation;
- }
- }
-
- public ICollection<ProjectProperty> Properties
- {
- [DebuggerStepThrough]
- get
- {
- return new ReadOnlyCollection<ProjectProperty>(this.data.Properties);
- }
- }
-
- public bool SkipEvaluation
- {
- [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.<SkipEvaluation>k__BackingField;
- }
- [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- set
- {
- this.<SkipEvaluation>k__BackingField = value;
- }
- }
-
- public IDictionary<string, ProjectTargetInstance> Targets
- {
- [DebuggerStepThrough]
- get
- {
- return ReadOnlyDictionary<string, ProjectTargetInstance>.CreateWrapper(this.data.Targets);
- }
- }
-
- public string ToolsVersion
- {
- get
- {
- return this.data.Toolset.ToolsVersion;
- }
- }
-
- public ProjectRootElement Xml
- {
- [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.xml;
- }
- }
-
-
- private enum BuildEnabledSetting
- {
- BuildEnabled,
- BuildDisabled,
- UseProjectCollectionSetting
- }
-
- internal class Data : IEvaluatorData<ProjectProperty, ProjectItem, ProjectMetadata, ProjectItemDefinition>, IPropertyProvider<ProjectProperty>, IItemProvider<ProjectItem>
- {
- private readonly PropertyDictionary<ProjectPropertyInstance> globalProperties;
- private ItemDictionary<ProjectItem> items;
- private MultiDictionary<string, ProjectItem> itemsByEvaluatedInclude;
- private string originalProjectToolsVersion;
- private readonly Microsoft.Build.Evaluation.Project project;
- private bool treatingHigherToolsVersionsAs40;
-
- internal Data(Microsoft.Build.Evaluat…
Large files files are truncated, but you can click here to view the full file