/Microsoft.Build/Microsoft.Build/Microsoft/Build/Execution/ProjectInstance.cs
C# | 1151 lines | 1047 code | 104 blank | 0 comment | 78 complexity | 34263f108fa06fd07b3959a9067d6120 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.Execution
- {
- using Microsoft.Build.BackEnd;
- using Microsoft.Build.BackEnd.Logging;
- using Microsoft.Build.BuildEngine;
- using Microsoft.Build.Collections;
- using Microsoft.Build.Construction;
- using Microsoft.Build.Evaluation;
- using Microsoft.Build.Exceptions;
- using Microsoft.Build.Framework;
- using Microsoft.Build.Internal;
- using Microsoft.Build.Shared;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Diagnostics;
- using System.IO;
- using System.Runtime;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
- using System.Xml;
-
- [DebuggerDisplay("{FullPath} #Targets={TargetsCount} DefaultTargets={(DefaultTargets == null) ? System.String.Empty : System.String.Join(\";\", DefaultTargets.ToArray())} ToolsVersion={Toolset.ToolsVersion} InitialTargets={(InitialTargets == null) ? System.String.Empty : System.String.Join(\";\", InitialTargets.ToArray())} #GlobalProperties={globalProperties.Count} #Properties={properties.Count} #ItemTypes={items.ItemTypes.Count} #Items={items.Count}")]
- public class ProjectInstance : IEvaluatorData<ProjectPropertyInstance, ProjectItemInstance, ProjectMetadataInstance, ProjectItemDefinitionInstance>, IPropertyProvider<ProjectPropertyInstance>, IItemProvider<ProjectItemInstance>
- {
- private Dictionary<string, ProjectTargetInstance> actualTargets;
- private string directory;
- private PropertyDictionary<ProjectPropertyInstance> environmentVariableProperties;
- private bool explicitToolsVersionSpecified;
- private PropertyDictionary<ProjectPropertyInstance> globalProperties;
- private HostServices hostServices;
- private IDictionary<string, object> initialGlobalsForDebugging;
- private Dictionary<string, ProjectItemDefinitionInstance> itemDefinitions;
- private ItemDictionary<ProjectItemInstance> items;
- private string originalProjectToolsVersion;
- private IElementLocation projectFileLocation;
- private PropertyDictionary<ProjectPropertyInstance> properties;
- private ReadOnlyDictionary<string, ProjectTargetInstance> targets;
- private bool treatingHigherToolsVersionsAs40;
-
- public ProjectInstance(ProjectRootElement xml) : this(xml, null, null, ProjectCollection.GlobalProjectCollection)
- {
- }
-
- private ProjectInstance(ProjectInstance that)
- {
- this.directory = that.directory;
- this.projectFileLocation = that.projectFileLocation;
- this.hostServices = that.hostServices;
- this.properties = new PropertyDictionary<ProjectPropertyInstance>(that.properties.Count);
- foreach (ProjectPropertyInstance instance in that.Properties)
- {
- this.properties.Set(instance.DeepClone());
- }
- this.items = new ItemDictionary<ProjectItemInstance>(that.items.ItemTypes.Count);
- foreach (ProjectItemInstance instance2 in that.Items)
- {
- this.items.Add(instance2.DeepClone());
- }
- this.globalProperties = new PropertyDictionary<ProjectPropertyInstance>(that.globalProperties.Count);
- foreach (ProjectPropertyInstance instance3 in that.GlobalPropertiesDictionary)
- {
- this.globalProperties.Set(instance3.DeepClone());
- }
- this.environmentVariableProperties = new PropertyDictionary<ProjectPropertyInstance>(that.environmentVariableProperties.Count);
- foreach (ProjectPropertyInstance instance4 in that.environmentVariableProperties)
- {
- this.environmentVariableProperties.Set(instance4.DeepClone());
- }
- this.DefaultTargets = new List<string>(that.DefaultTargets);
- this.InitialTargets = new List<string>(that.InitialTargets);
- this.Toolset = that.Toolset;
- this.targets = that.targets;
- this.itemDefinitions = that.itemDefinitions;
- this.ProjectRootElementCache = that.ProjectRootElementCache;
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public ProjectInstance(string projectFile) : this(projectFile, (IDictionary<string, string>) null, (string) null)
- {
- }
-
- internal ProjectInstance(string projectFile, ProjectInstance projectToInheritFrom, IDictionary<string, string> globalProperties)
- {
- this.projectFileLocation = new ElementLocation(projectFile);
- this.globalProperties = new PropertyDictionary<ProjectPropertyInstance>(globalProperties.Count);
- this.Toolset = projectToInheritFrom.Toolset;
- this.properties = new PropertyDictionary<ProjectPropertyInstance>(projectToInheritFrom.properties);
- this.items = new ItemDictionary<ProjectItemInstance>();
- this.actualTargets = new Dictionary<string, ProjectTargetInstance>(StringComparer.OrdinalIgnoreCase);
- this.targets = ReadOnlyDictionary<string, ProjectTargetInstance>.CreateWrapper(this.actualTargets);
- this.environmentVariableProperties = projectToInheritFrom.environmentVariableProperties;
- this.itemDefinitions = new Dictionary<string, ProjectItemDefinitionInstance>(projectToInheritFrom.itemDefinitions, MSBuildNameIgnoreCaseComparer.Default);
- this.hostServices = projectToInheritFrom.hostServices;
- this.ProjectRootElementCache = projectToInheritFrom.ProjectRootElementCache;
- this.explicitToolsVersionSpecified = projectToInheritFrom.explicitToolsVersionSpecified;
- this.InitialTargets = new List<string>();
- this.DefaultTargets = new List<string>();
- this.DefaultTargets.Add("Build");
- this.TaskRegistry = projectToInheritFrom.TaskRegistry;
- IEvaluatorData<ProjectPropertyInstance, ProjectItemInstance, ProjectMetadataInstance, ProjectItemDefinitionInstance> data = this;
- data.AfterTargets = new Dictionary<string, List<TargetSpecification>>();
- data.BeforeTargets = new Dictionary<string, List<TargetSpecification>>();
- foreach (KeyValuePair<string, string> pair in globalProperties)
- {
- this.globalProperties[pair.Key] = new ProjectPropertyInstance(pair.Key, pair.Value);
- }
- }
-
- public ProjectInstance(string projectFile, IDictionary<string, string> globalProperties, string toolsVersion) : this(projectFile, globalProperties, toolsVersion, ProjectCollection.GlobalProjectCollection)
- {
- }
-
- public ProjectInstance(ProjectRootElement xml, IDictionary<string, string> globalProperties, string toolsVersion, ProjectCollection projectCollection)
- {
- BuildEventContext buildEventContext = new BuildEventContext(0, -1, -2, -1);
- this.Initialize(xml, globalProperties, toolsVersion, new BuildParameters(projectCollection), projectCollection.LoggingService, buildEventContext);
- }
-
- public ProjectInstance(string projectFile, IDictionary<string, string> globalProperties, string toolsVersion, ProjectCollection projectCollection)
- {
- ErrorUtilities.VerifyThrowArgumentLength(projectFile, "projectFile");
- ErrorUtilities.VerifyThrowArgumentLengthIfNotNull(toolsVersion, "toolsVersion");
- projectFile = FileUtilities.NormalizePath(projectFile);
- BuildParameters buildParameters = new BuildParameters(projectCollection);
- BuildEventContext buildEventContext = new BuildEventContext(buildParameters.NodeId, -1, -2, -1);
- ProjectRootElement xml = ProjectRootElement.OpenProjectOrSolution(projectFile, globalProperties, toolsVersion, projectCollection.LoggingService, buildParameters.ProjectRootElementCache, buildEventContext);
- this.Initialize(xml, globalProperties, toolsVersion, buildParameters, projectCollection.LoggingService, buildEventContext);
- }
-
- internal ProjectInstance(Microsoft.Build.Evaluation.Project.Data data, string directory, string fullPath, HostServices hostServices, PropertyDictionary<ProjectPropertyInstance> environmentVariableProperties)
- {
- ErrorUtilities.VerifyThrowInternalNull(data, "data");
- ErrorUtilities.VerifyThrowInternalLength(directory, "directory");
- ErrorUtilities.VerifyThrowArgumentLengthIfNotNull(fullPath, "fullPath");
- this.directory = directory;
- this.projectFileLocation = new ElementLocation(fullPath);
- this.hostServices = hostServices;
- this.properties = new PropertyDictionary<ProjectPropertyInstance>(data.Properties.Count);
- foreach (ProjectProperty property in data.Properties)
- {
- ProjectPropertyInstance projectProperty = new ProjectPropertyInstance(property.Name, ((IProperty) property).EvaluatedValueEscaped, true);
- this.properties.Set(projectProperty);
- }
- this.itemDefinitions = new Dictionary<string, ProjectItemDefinitionInstance>(MSBuildNameIgnoreCaseComparer.Default);
- foreach (ProjectItemDefinition definition in data.ItemDefinitions.Values)
- {
- this.itemDefinitions.Add(definition.ItemType, new ProjectItemDefinitionInstance(this, definition));
- }
- this.items = new ItemDictionary<ProjectItemInstance>(data.ItemTypes.Count);
- foreach (ProjectItem item in data.Items)
- {
- List<ProjectItemDefinitionInstance> itemDefinitions = null;
- if (item.InheritedItemDefinitions != null)
- {
- itemDefinitions = new List<ProjectItemDefinitionInstance>(item.InheritedItemDefinitions.Count);
- foreach (ProjectItemDefinition definition2 in item.InheritedItemDefinitions)
- {
- itemDefinitions.Add(this.itemDefinitions[definition2.ItemType]);
- }
- }
- CopyOnWritePropertyDictionary<ProjectMetadataInstance> directMetadata = null;
- if (item.DirectMetadata != null)
- {
- directMetadata = new CopyOnWritePropertyDictionary<ProjectMetadataInstance>(item.DirectMetadataCount);
- foreach (ProjectMetadata metadata in item.DirectMetadata)
- {
- ProjectMetadataInstance instance2 = new ProjectMetadataInstance(metadata);
- directMetadata.Set(instance2);
- }
- }
- ProjectItemInstance projectItem = new ProjectItemInstance(this, item.ItemType, ((IItem) item).EvaluatedIncludeEscaped, item.EvaluatedIncludeBeforeWildcardExpansionEscaped, directMetadata, item.BuiltInMetadata, itemDefinitions);
- this.items.Add(projectItem);
- }
- this.globalProperties = new PropertyDictionary<ProjectPropertyInstance>(data.GlobalPropertiesDictionary.Count);
- foreach (ProjectPropertyInstance instance4 in data.GlobalPropertiesDictionary)
- {
- this.globalProperties.Set(instance4.DeepClone());
- }
- this.environmentVariableProperties = new PropertyDictionary<ProjectPropertyInstance>(environmentVariableProperties.Count);
- foreach (ProjectPropertyInstance instance5 in environmentVariableProperties)
- {
- this.environmentVariableProperties.Set(instance5.DeepClone());
- }
- this.DefaultTargets = new List<string>(data.DefaultTargets);
- this.InitialTargets = new List<string>(data.InitialTargets);
- this.BeforeTargets = ReadOnlyDictionary<string, List<TargetSpecification>>.CreateClone(data.BeforeTargets, StringComparer.OrdinalIgnoreCase);
- this.AfterTargets = ReadOnlyDictionary<string, List<TargetSpecification>>.CreateClone(data.AfterTargets, StringComparer.OrdinalIgnoreCase);
- this.targets = ReadOnlyDictionary<string, ProjectTargetInstance>.CreateClone(data.Targets, StringComparer.OrdinalIgnoreCase);
- this.Toolset = data.Toolset;
- this.TaskRegistry = data.TaskRegistry;
- this.ProjectRootElementCache = data.Project.ProjectCollection.ProjectRootElementCache;
- this.treatingHigherToolsVersionsAs40 = data.TreatingHigherToolsVersionsAs40;
- this.originalProjectToolsVersion = data.OriginalProjectToolsVersion;
- this.explicitToolsVersionSpecified = data.ExplicitToolsVersion != null;
- }
-
- internal ProjectInstance(ProjectRootElement xml, IDictionary<string, string> globalProperties, string toolsVersion, BuildParameters buildParameters, ILoggingService loggingService, BuildEventContext buildEventContext)
- {
- ErrorUtilities.VerifyThrowArgumentNull(xml, "xml");
- ErrorUtilities.VerifyThrowArgumentLengthIfNotNull(toolsVersion, "toolsVersion");
- ErrorUtilities.VerifyThrowArgumentNull(buildParameters, "buildParameters");
- this.Initialize(xml, globalProperties, toolsVersion, buildParameters, loggingService, buildEventContext);
- }
-
- internal ProjectInstance(string projectFile, IDictionary<string, string> globalProperties, string toolsVersion, BuildParameters buildParameters, ILoggingService loggingService, BuildEventContext buildEventContext)
- {
- ErrorUtilities.VerifyThrowArgumentLength(projectFile, "projectFile");
- ErrorUtilities.VerifyThrowArgumentLengthIfNotNull(toolsVersion, "toolsVersion");
- ErrorUtilities.VerifyThrowArgumentNull(buildParameters, "buildParameters");
- ProjectRootElement xml = ProjectRootElement.OpenProjectOrSolution(projectFile, globalProperties, toolsVersion, loggingService, buildParameters.ProjectRootElementCache, buildEventContext);
- this.Initialize(xml, globalProperties, toolsVersion, buildParameters, loggingService, buildEventContext);
- }
-
- public ProjectItemInstance AddItem(string itemType, string evaluatedInclude)
- {
- ProjectItemInstance projectItem = new ProjectItemInstance(this, itemType, evaluatedInclude);
- this.items.Add(projectItem);
- return projectItem;
- }
-
- public ProjectItemInstance AddItem(string itemType, string evaluatedInclude, IEnumerable<KeyValuePair<string, string>> metadata)
- {
- ProjectItemInstance projectItem = new ProjectItemInstance(this, itemType, evaluatedInclude, metadata);
- this.items.Add(projectItem);
- return projectItem;
- }
-
- internal ProjectTargetInstance AddTarget(string targetName, string condition, string inputs, string outputs, string returns, string keepDuplicateOutputs, string dependsOnTargets, bool parentProjectSupportsReturnsAttribute)
- {
- ErrorUtilities.VerifyThrowInternalLength(targetName, "targetName");
- ErrorUtilities.VerifyThrow(!this.actualTargets.ContainsKey(targetName), "Target {0} already exists.", targetName);
- ProjectTargetInstance instance = new ProjectTargetInstance(targetName, condition ?? string.Empty, inputs ?? string.Empty, outputs ?? string.Empty, returns, keepDuplicateOutputs ?? string.Empty, dependsOnTargets ?? string.Empty, this.projectFileLocation, string.IsNullOrEmpty(condition) ? null : ((IElementLocation) ElementLocation.EmptyLocation), string.IsNullOrEmpty(inputs) ? null : ((IElementLocation) ElementLocation.EmptyLocation), string.IsNullOrEmpty(outputs) ? null : ((IElementLocation) ElementLocation.EmptyLocation), string.IsNullOrEmpty(returns) ? null : ((IElementLocation) ElementLocation.EmptyLocation), string.IsNullOrEmpty(keepDuplicateOutputs) ? null : ((IElementLocation) ElementLocation.EmptyLocation), string.IsNullOrEmpty(dependsOnTargets) ? null : ((IElementLocation) ElementLocation.EmptyLocation), null, null, new System.Collections.ObjectModel.ReadOnlyCollection<ProjectTargetInstanceChild>(new List<ProjectTargetInstanceChild>()), new System.Collections.ObjectModel.ReadOnlyCollection<ProjectOnErrorInstance>(new List<ProjectOnErrorInstance>()), parentProjectSupportsReturnsAttribute);
- this.actualTargets[instance.Name] = instance;
- return instance;
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public bool Build()
- {
- return this.Build(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, (IEnumerable<ForwardingLoggerRecord>) 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);
- }
-
- [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, (IEnumerable<ForwardingLoggerRecord>) null);
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public bool Build(string[] targets, IEnumerable<ILogger> loggers, out IDictionary<string, TargetResult> targetOutputs)
- {
- return this.Build(targets, loggers, null, null, out targetOutputs);
- }
-
- public bool Build(string[] targets, IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers)
- {
- IDictionary<string, TargetResult> dictionary;
- return this.Build(targets, loggers, remoteLoggers, out dictionary);
- }
-
- public bool Build(string target, IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers)
- {
- string[] targets = (target == null) ? new string[0] : new string[] { target };
- return this.Build(targets, loggers, remoteLoggers);
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public bool Build(string[] targets, IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers, out IDictionary<string, TargetResult> targetOutputs)
- {
- return this.Build(targets, loggers, remoteLoggers, null, out targetOutputs);
- }
-
- internal bool Build(string[] targets, IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers, ILoggingService loggingService, out IDictionary<string, TargetResult> targetOutputs)
- {
- if (targets == null)
- {
- targets = new string[0];
- }
- BuildManager defaultBuildManager = BuildManager.DefaultBuildManager;
- BuildRequestData requestData = new BuildRequestData(this, targets, this.hostServices);
- BuildParameters parameters = new BuildParameters();
- if (loggers != null)
- {
- parameters.Loggers = (loggers is ICollection<ILogger>) ? ((ICollection<ILogger>) loggers) : new List<ILogger>(loggers);
- }
- if (remoteLoggers != null)
- {
- parameters.ForwardingLoggers = (remoteLoggers is ICollection<ForwardingLoggerRecord>) ? ((ICollection<ForwardingLoggerRecord>) remoteLoggers) : new List<ForwardingLoggerRecord>(remoteLoggers);
- }
- parameters.EnvironmentPropertiesInternal = this.environmentVariableProperties;
- parameters.ProjectRootElementCache = this.ProjectRootElementCache;
- Microsoft.Build.Execution.BuildResult result = defaultBuildManager.Build(parameters, requestData);
- targetOutputs = result.ResultsByTarget;
- return (result.OverallResult == BuildResultCode.Success);
- }
-
- internal void Cache(INodePacketTranslator translator)
- {
- this.Translate(translator);
- if (translator.Mode == TranslationDirection.WriteToStream)
- {
- this.globalProperties = null;
- this.properties = null;
- this.items = null;
- }
- }
-
- public ProjectInstance DeepCopy()
- {
- return new ProjectInstance(this);
- }
-
- public bool EvaluateCondition(string condition)
- {
- Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(this, this);
- return ConditionEvaluator.EvaluateCondition<ProjectPropertyInstance, ProjectItemInstance>(condition, Microsoft.Build.Evaluation.ParserOptions.AllowPropertiesAndItemLists, expander, Microsoft.Build.Evaluation.ExpanderOptions.ExpandPropertiesAndItems, this.Directory, this.ProjectFileLocation, null, BuildEventContext.Invalid);
- }
-
- public string ExpandString(string unexpandedValue)
- {
- Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(this, this);
- return expander.ExpandIntoStringAndUnescape(unexpandedValue, Microsoft.Build.Evaluation.ExpanderOptions.ExpandPropertiesAndItems, this.ProjectFileLocation);
- }
-
- private static ProjectInstance[] GenerateSolutionWrapper(string projectFile, IDictionary<string, string> globalProperties, string toolsVersion, ILoggingService loggingService, BuildEventContext projectBuildEventContext)
- {
- SolutionParser solution = new SolutionParser {
- SolutionFile = projectFile
- };
- solution.ParseSolutionFile();
- if (solution.SolutionParserComments.Count > 0)
- {
- foreach (string str in solution.SolutionParserComments)
- {
- loggingService.LogCommentFromText(projectBuildEventContext, MessageImportance.Low, str);
- }
- }
- return SolutionProjectGenerator.Generate(solution, globalProperties, toolsVersion, projectBuildEventContext, loggingService);
- }
-
- [MethodImpl(MethodImplOptions.NoInlining)]
- private static ProjectInstance[] GenerateSolutionWrapperUsingOldOM(string projectFile, IDictionary<string, string> globalProperties, string toolsVersion, Microsoft.Build.Evaluation.ProjectRootElementCache projectRootElementCache, BuildParameters buildParameters, ILoggingService loggingService, BuildEventContext projectBuildEventContext)
- {
- string str;
- List<DictionaryEntry> list = null;
- try
- {
- foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables())
- {
- string key = entry.Key as string;
- if ((key != null) && ((!XmlUtilities.IsValidElementName(key) || (XMakeElements.IllegalItemPropertyNames[key] != null)) || Microsoft.Build.Internal.ReservedPropertyNames.IsReservedProperty(key)))
- {
- if (list == null)
- {
- list = new List<DictionaryEntry>();
- }
- Environment.SetEnvironmentVariable(key, null);
- list.Add(entry);
- }
- }
- str = SolutionWrapperProject.Generate(projectFile, toolsVersion, projectBuildEventContext);
- }
- catch (Microsoft.Build.BuildEngine.InvalidProjectFileException exception)
- {
- throw new Microsoft.Build.Exceptions.InvalidProjectFileException(exception.ProjectFile, exception.LineNumber, exception.ColumnNumber, exception.EndLineNumber, exception.EndColumnNumber, exception.Message, exception.ErrorSubcategory, exception.ErrorCode, exception.HelpKeyword, exception.InnerException);
- }
- finally
- {
- if (list != null)
- {
- foreach (DictionaryEntry entry2 in list)
- {
- Environment.SetEnvironmentVariable(entry2.Key as string, entry2.Value as string);
- }
- }
- }
- ProjectRootElement xml = new ProjectRootElement(XmlReader.Create(new StringReader(str)), projectRootElementCache) {
- DirectoryPath = Path.GetDirectoryName(projectFile)
- };
- ProjectInstance instance = new ProjectInstance(xml, globalProperties, toolsVersion, buildParameters, loggingService, projectBuildEventContext);
- return new ProjectInstance[] { instance };
- }
-
- public static string GetEvaluatedItemIncludeEscaped(ProjectItemDefinitionInstance item)
- {
- ErrorUtilities.VerifyThrowArgumentNull(item, "item");
- return ((IItem) item).EvaluatedIncludeEscaped;
- }
-
- public static string GetEvaluatedItemIncludeEscaped(ProjectItemInstance item)
- {
- ErrorUtilities.VerifyThrowArgumentNull(item, "item");
- return ((IItem) item).EvaluatedIncludeEscaped;
- }
-
- public ICollection<ProjectItemInstance> GetItems(string itemType)
- {
- return ((IItemProvider<ProjectItemInstance>) this).GetItems(itemType);
- }
-
- public static string GetMetadataValueEscaped(ProjectMetadataInstance metadatum)
- {
- ErrorUtilities.VerifyThrowArgumentNull(metadatum, "metadatum");
- return metadatum.EvaluatedValueEscaped;
- }
-
- public static string GetMetadataValueEscaped(ProjectItemDefinitionInstance item, string name)
- {
- ErrorUtilities.VerifyThrowArgumentNull(item, "item");
- return ((IItem) item).GetMetadataValueEscaped(name);
- }
-
- public static string GetMetadataValueEscaped(ProjectItemInstance item, string name)
- {
- ErrorUtilities.VerifyThrowArgumentNull(item, "item");
- return ((IItem) item).GetMetadataValueEscaped(name);
- }
-
- [DebuggerStepThrough]
- public ProjectPropertyInstance GetProperty(string name)
- {
- return this.properties[name];
- }
-
- public string GetPropertyValue(string name)
- {
- ProjectPropertyInstance instance = this.properties[name];
- return ((instance == null) ? string.Empty : instance.EvaluatedValue);
- }
-
- public static string GetPropertyValueEscaped(ProjectPropertyInstance property)
- {
- ErrorUtilities.VerifyThrowArgumentNull(property, "property");
- return ((IProperty) property).EvaluatedValueEscaped;
- }
-
- internal IList<TargetSpecification> GetTargetsWhichRunAfter(string target)
- {
- List<TargetSpecification> list;
- if (this.AfterTargets.TryGetValue(target, out list))
- {
- return list;
- }
- return ReadOnlyEmptyList<TargetSpecification>.Instance;
- }
-
- internal IList<TargetSpecification> GetTargetsWhichRunBefore(string target)
- {
- List<TargetSpecification> list;
- if (this.BeforeTargets.TryGetValue(target, out list))
- {
- return list;
- }
- return ReadOnlyEmptyList<TargetSpecification>.Instance;
- }
-
- private void Initialize(ProjectRootElement xml, IDictionary<string, string> globalProperties, string explicitToolsVersion, BuildParameters buildParameters, ILoggingService loggingService, BuildEventContext buildEventContext)
- {
- Version version;
- ErrorUtilities.VerifyThrowArgumentNull(xml, "xml");
- ErrorUtilities.VerifyThrowArgumentLengthIfNotNull(explicitToolsVersion, "toolsVersion");
- ErrorUtilities.VerifyThrowArgumentNull(buildParameters, "buildParameters");
- this.directory = xml.DirectoryPath;
- this.projectFileLocation = (xml.ProjectFileLocation != null) ? xml.ProjectFileLocation : ElementLocation.EmptyLocation;
- this.properties = new PropertyDictionary<ProjectPropertyInstance>();
- this.items = new ItemDictionary<ProjectItemInstance>();
- this.actualTargets = new Dictionary<string, ProjectTargetInstance>(StringComparer.OrdinalIgnoreCase);
- this.targets = ReadOnlyDictionary<string, ProjectTargetInstance>.CreateWrapper(this.actualTargets);
- this.globalProperties = new PropertyDictionary<ProjectPropertyInstance>((globalProperties == null) ? 0 : globalProperties.Count);
- this.environmentVariableProperties = buildParameters.EnvironmentPropertiesInternal;
- this.itemDefinitions = new Dictionary<string, ProjectItemDefinitionInstance>(MSBuildNameIgnoreCaseComparer.Default);
- this.hostServices = buildParameters.HostServices;
- this.ProjectRootElementCache = buildParameters.ProjectRootElementCache;
- string toolsVersion = explicitToolsVersion;
- this.explicitToolsVersionSpecified = explicitToolsVersion != null;
- IElementLocation elementLocation = xml.Location;
- if (((Environment.GetEnvironmentVariable("MSBUILDTREATHIGHERTOOLSVERSIONASCURRENT") == "1") && Version.TryParse(xml.ToolsVersion, out version)) && ((version.Major >= 4) && (version.Minor > 0)))
- {
- toolsVersion = "4.0";
- this.treatingHigherToolsVersionsAs40 = true;
- this.originalProjectToolsVersion = xml.ToolsVersion;
- }
- if (toolsVersion == null)
- {
- if (xml.ToolsVersion.Length > 0)
- {
- toolsVersion = xml.ToolsVersion;
- elementLocation = xml.ToolsVersionLocation;
- this.originalProjectToolsVersion = toolsVersion;
- if (buildParameters.GetToolset(toolsVersion) == null)
- {
- toolsVersion = "4.0";
- this.treatingHigherToolsVersionsAs40 = true;
- }
- }
- else
- {
- toolsVersion = buildParameters.DefaultToolsVersion;
- }
- }
- this.Toolset = buildParameters.GetToolset(toolsVersion);
- if (this.Toolset == null)
- {
- string str2 = Microsoft.Build.Internal.Utilities.CreateToolsVersionListString(buildParameters.Toolsets);
- ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "UnrecognizedToolsVersion", toolsVersion, str2);
- }
- this.TaskRegistry = new Microsoft.Build.Execution.TaskRegistry(this.Toolset, this.ProjectRootElementCache);
- if (globalProperties != null)
- {
- foreach (KeyValuePair<string, string> pair in globalProperties)
- {
- this.globalProperties.Set(new ProjectPropertyInstance(pair.Key, pair.Value));
- }
- }
- this.initialGlobalsForDebugging = Evaluator<ProjectPropertyInstance, ProjectItemInstance, ProjectMetadataInstance, ProjectItemDefinitionInstance>.Evaluate(this, xml, Microsoft.Build.Evaluation.ProjectLoadSettings.Default, buildParameters.MaxNodeCount, buildParameters.EnvironmentPropertiesInternal, loggingService, new ProjectItemInstance.TaskItem.ProjectItemInstanceFactory(this), buildParameters.ToolsetProvider, this.ProjectRootElementCache, buildEventContext, this);
- }
-
- internal static ProjectInstance[] LoadSolutionForBuild(string projectFile, PropertyDictionary<ProjectPropertyInstance> globalPropertiesInstances, string toolsVersion, BuildParameters buildParameters, ILoggingService loggingService, BuildEventContext projectBuildEventContext)
- {
- ErrorUtilities.VerifyThrowArgumentLength(projectFile, "projectFile");
- ErrorUtilities.VerifyThrowArgumentNull(globalPropertiesInstances, "globalPropertiesInstances");
- ErrorUtilities.VerifyThrowArgumentLengthIfNotNull(toolsVersion, "toolsVersion");
- ErrorUtilities.VerifyThrowArgumentNull(buildParameters, "buildParameters");
- ErrorUtilities.VerifyThrow(FileUtilities.IsSolutionFilename(projectFile), "Project file {0} is not a solution.", projectFile);
- ProjectInstance[] instanceArray = null;
- Dictionary<string, string> globalProperties = new Dictionary<string, string>(globalPropertiesInstances.Count, StringComparer.OrdinalIgnoreCase);
- foreach (ProjectPropertyInstance instance in globalPropertiesInstances)
- {
- globalProperties[instance.Name] = ((IProperty) instance).EvaluatedValueEscaped;
- }
- if (toolsVersion != null)
- {
- if ((string.Equals(toolsVersion, "2.0", StringComparison.OrdinalIgnoreCase) || string.Equals(toolsVersion, "3.0", StringComparison.OrdinalIgnoreCase)) || string.Equals(toolsVersion, "3.5", StringComparison.OrdinalIgnoreCase))
- {
- loggingService.LogComment(projectBuildEventContext, MessageImportance.Low, "OldWrapperGeneratedExplicitToolsVersion", new object[] { toolsVersion });
- return GenerateSolutionWrapperUsingOldOM(projectFile, globalProperties, toolsVersion, buildParameters.ProjectRootElementCache, buildParameters, loggingService, projectBuildEventContext);
- }
- return GenerateSolutionWrapper(projectFile, globalProperties, toolsVersion, loggingService, projectBuildEventContext);
- }
- if (toolsVersion != null)
- {
- return instanceArray;
- }
- int solutionFileMajorVersion = SolutionParser.GetSolutionFileMajorVersion(projectFile);
- if (solutionFileMajorVersion <= 9)
- {
- loggingService.LogComment(projectBuildEventContext, MessageImportance.Low, "OldWrapperGeneratedOldSolutionVersion", new object[] { "2.0", solutionFileMajorVersion });
- return GenerateSolutionWrapperUsingOldOM(projectFile, globalProperties, "2.0", buildParameters.ProjectRootElementCache, buildParameters, loggingService, projectBuildEventContext);
- }
- if (solutionFileMajorVersion == 10)
- {
- loggingService.LogComment(projectBuildEventContext, MessageImportance.Low, "OldWrapperGeneratedOldSolutionVersion", new object[] { "3.5", solutionFileMajorVersion });
- return GenerateSolutionWrapperUsingOldOM(projectFile, globalProperties, "3.5", buildParameters.ProjectRootElementCache, buildParameters, loggingService, projectBuildEventContext);
- }
- return GenerateSolutionWrapper(projectFile, globalProperties, toolsVersion, loggingService, projectBuildEventContext);
- }
-
- void IEvaluatorData<ProjectPropertyInstance, ProjectItemInstance, ProjectMetadataInstance, ProjectItemDefinitionInstance>.AddItem(ProjectItemInstance item)
- {
- this.items.Add(item);
- }
-
- IItemDefinition<ProjectMetadataInstance> IEvaluatorData<ProjectPropertyInstance, ProjectItemInstance, ProjectMetadataInstance, ProjectItemDefinitionInstance>.AddItemDefinition(string itemType)
- {
- ProjectItemDefinitionInstance instance = new ProjectItemDefinitionInstance(this, itemType);
- this.itemDefinitions.Add(itemType, instance);
- return instance;
- }
-
- void IEvaluatorData<ProjectPropertyInstance, ProjectItemInstance, ProjectMetadataInstance, ProjectItemDefinitionInstance>.AddItemIgnoringCondition(ProjectItemInstance item)
- {
- ErrorUtilities.ThrowInternalErrorUnreachable();
- }
-
- void IEvaluatorData<ProjectPropertyInstance, ProjectItemInstance, ProjectMetadataInstance, ProjectItemDefinitionInstance>.AddTarget(ProjectTargetInstance target)
- {
- this.actualTargets[target.Name] = target;
- }
-
- void IEvaluatorData<ProjectPropertyInstance, ProjectItemInstance, ProjectMetadataInstance, ProjectItemDefinitionInstance>.AddToAllEvaluatedItemDefinitionMetadataList(ProjectMetadataInstance itemDefinitionMetadatum)
- {
- ErrorUtilities.ThrowInternalErrorUnreachable();
- }
-
- void IEvaluatorData<ProjectPropertyInstance, ProjectItemInstance, ProjectMetadataInstance, ProjectItemDefinitionInstance>.AddToAllEvaluatedItemsList(ProjectItemInstance item)
- {
- ErrorUtilities.ThrowInternalErrorUnreachable();
- }
-
- void IEvaluatorData<ProjectPropertyInstance, ProjectItemInstance, ProjectMetadataInstance, ProjectItemDefinitionInstance>.AddToAllEvaluatedPropertiesList(ProjectPropertyInstance property)
- {
- ErrorUtilities.ThrowInternalErrorUnreachable();
- }
-
- IItemDefinition<ProjectMetadataInstance> IEvaluatorData<ProjectPropertyInstance, ProjectItemInstance, ProjectMetadataInstance, ProjectItemDefinitionInstance>.GetItemDefinition(string itemType)
- {
- ProjectItemDefinitionInstance instance;
- this.itemDefinitions.TryGetValue(itemType, out instance);
- return instance;
- }
-
- ProjectTargetInstance IEvaluatorData<ProjectPropertyInstance, ProjectItemInstance, ProjectMetadataInstance, ProjectItemDefinitionInstance>.GetTarget(string targetName)
- {
- ProjectTargetInstance instance;
- this.targets.TryGetValue(targetName, out instance);
- return instance;
- }
-
- void IEvaluatorData<ProjectPropertyInstance, ProjectItemInstance, ProjectMetadataInstance, ProjectItemDefinitionInstance>.InitializeForEvaluation(IToolsetProvider toolsetProvider)
- {
- }
-
- void IEvaluatorData<ProjectPropertyInstance, ProjectItemInstance, ProjectMetadataInstance, ProjectItemDefinitionInstance>.RecordImport(ProjectImportElement importElement, ProjectRootElement import, int versionEvaluated)
- {
- }
-
- void IEvaluatorData<ProjectPropertyInstance, ProjectItemInstance, ProjectMetadataInstance, ProjectItemDefinitionInstance>.RecordImportWithDuplicates(ProjectImportElement importElement, ProjectRootElement import, int versionEvaluated)
- {
- }
-
- ProjectPropertyInstance IEvaluatorData<ProjectPropertyInstance, ProjectItemInstance, ProjectMetadataInstance, ProjectItemDefinitionInstance>.SetProperty(ProjectPropertyElement propertyElement, string evaluatedValueEscaped, ProjectPropertyInstance predecessor)
- {
- ProjectPropertyInstance projectProperty = new ProjectPropertyInstance(propertyElement.Name, evaluatedValueEscaped);
- this.properties.Set(projectProperty);
- return projectProperty;
- }
-
- ProjectPropertyInstance IEvaluatorData<ProjectPropertyInstance, ProjectItemInstance, ProjectMetadataInstance, ProjectItemDefinitionInstance>.SetProperty(string name, string evaluatedValueEscaped, bool isGlobalProperty, bool mayBeReserved)
- {
- ProjectPropertyInstance projectProperty = new ProjectPropertyInstance(name, evaluatedValueEscaped, mayBeReserved);
- this.properties.Set(projectProperty);
- return projectProperty;
- }
-
- ICollection<ProjectItemInstance> IItemProvider<ProjectItemInstance>.GetItems(string itemType)
- {
- return this.items[itemType];
- }
-
- [DebuggerStepThrough]
- ProjectPropertyInstance IPropertyProvider<ProjectPropertyInstance>.GetProperty(string name, int startIndex, int endIndex)
- {
- return this.properties.GetProperty(name, startIndex, endIndex);
- }
-
- public bool RemoveItem(ProjectItemInstance item)
- {
- return this.items.Remove(item);
- }
-
- public bool RemoveProperty(string name)
- {
- return this.properties.Remove(name);
- }
-
- internal void RemoveTarget(string targetName)
- {
- this.actualTargets.Remove(targetName);
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- internal void RetrieveFromCache(INodePacketTranslator translator)
- {
- this.Translate(translator);
- }
-
- public ProjectPropertyInstance SetProperty(string name, string evaluatedValue)
- {
- ProjectPropertyInstance projectProperty = new ProjectPropertyInstance(name, evaluatedValue);
- this.properties.Set(projectProperty);
- return projectProperty;
- }
-
- public ProjectRootElement ToProjectRootElement()
- {
- ProjectRootElement rootElement = ProjectRootElement.Create();
- rootElement.InitialTargets = string.Join(";", this.InitialTargets.ToArray());
- rootElement.DefaultTargets = string.Join(";", this.DefaultTargets.ToArray());
- rootElement.ToolsVersion = this.ToolsVersion;
- ProjectItemDefinitionGroupElement parent = rootElement.AddItemDefinitionGroup();
- foreach (ProjectItemDefinitionInstance instance in this.itemDefinitions.Values)
- {
- instance.ToProjectItemDefinitionElement(parent);
- }
- foreach (string str in this.items.ItemTypes)
- {
- ProjectItemGroupElement element3 = rootElement.AddItemGroup();
- foreach (ProjectItemInstance instance2 in this.items.GetItems(str))
- {
- instance2.ToProjectItemElement(element3);
- }
- }
- ProjectPropertyGroupElement element4 = rootElement.AddPropertyGroup();
- foreach (ProjectPropertyInstance instance3 in this.properties)
- {
- if ((!Microsoft.Build.Internal.ReservedPropertyNames.IsReservedProperty(instance3.Name) && (!this.globalProperties.Contains(instance3.Name) || !string.Equals(this.globalProperties[instance3.Name].EvaluatedValue, instance3.EvaluatedValue, StringComparison.OrdinalIgnoreCase))) && (!this.environmentVariableProperties.Contains(instance3.Name) || !string.Equals(this.environmentVariableProperties[instance3.Name].EvaluatedValue, instance3.EvaluatedValue, StringComparison.OrdinalIgnoreCase)))
- {
- instance3.ToProjectPropertyElement(element4);
- }
- }
- foreach (ProjectTargetInstance instance4 in this.Targets.Values)
- {
- instance4.ToProjectTargetElement(rootElement);
- }
- return rootElement;
- }
-
- private void Translate(INodePacketTranslator translator)
- {
- NodePacketValueFactory<ProjectItemInstance> factory = null;
- NodePacketValueFactory<ProjectItemInstance> factory2 = null;
- translator.TranslateDictionary<PropertyDictionary<ProjectPropertyInstance>, ProjectPropertyInstance>(ref this.globalProperties, new NodePacketValueFactory<ProjectPropertyInstance>(ProjectPropertyInstance.FactoryForDeserialization));
- translator.TranslateDictionary<PropertyDictionary<ProjectPropertyInstance>, ProjectPropertyInstance>(ref this.properties, new NodePacketValueFactory<ProjectPropertyInstance>(ProjectPropertyInstance.FactoryForDeserialization));
- if (translator.Mode == TranslationDirection.ReadFromStream)
- {
- int num = 0;
- translator.Translate(ref num);
- this.items = new ItemDictionary<ProjectItemInstance>(num);
- for (int i = 0; i < num; i++)
- {
- int num3 = 0;
- translator.Translate(ref num3);
- for (int j = 0; j < num3; j++)
- {
- ProjectItemInstance instance = null;
- if (factory == null)
- {
- factory = outerTranslator => ProjectItemInstance.FactoryForDeserialization(translator, this);
- }
- translator.Translate<ProjectItemInstance>(ref instance, factory);
- this.items.Add(instance);
- }
- }
- }
- else
- {
- int count = this.items.ItemTypes.Count;
- translator.Translate(ref count);
- foreach (string str in this.items.ItemTypes)
- {
- ICollection<ProjectItemInstance> is2 = this.items[str];
- int num6 = is2.Count;
- translator.Translate(ref num6);
- foreach (ProjectItemInstance instance2 in is2)
- {
- ProjectItemInstance instance3 = instance2;
- if (factory2 == null)
- {
- factory2 = outerTranslator => ProjectItemInstance.FactoryForDeserialization(translator, this);
- }
- translator.Translate<ProjectItemInstance>(ref instance3, factory2);
- }
- }
- }
- }
-
- public List<string> DefaultTargets
- {
- [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.<DefaultTargets>k__BackingField;
- }
- [CompilerGenerated]
- private set
- {
- this.<DefaultTargets>k__BackingField = value;
- }
- }
-
- public string Directory
- {
- [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.directory;
- }
- }
-
- internal string ExplicitToolsVersion
- {
- get
- {
- if (!this.explicitToolsVersionSpecified)
- {
- return null;
- }
- return this.Toolset.ToolsVersion;
- }
- }
-
- internal bool ExplicitToolsVersionSpecified
- {
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.explicitToolsVersionSpecified;
- }
- }
-
- public string FullPath
- {
- [DebuggerStepThrough]
- get
- {
- return this.projectFileLocation.File;
- }
- }
-
- public IDictionary<string, string> GlobalProperties
- {
- [DebuggerStepThrough]
- get
- {
- if ((this.globalProperties == null) || (this.globalProperties.Count == 0))
- {
- return ReadOnlyEmptyDictionary<string, string>.Instance;
- }
- Dictionary<string, string> backing = new Dictionary<string, string>(this.globalProperties.Count, MSBuildNameIgnoreCaseComparer.Default);
- foreach (ProjectPropertyInstance instance in this.globalProperties)
- {
- backing[instance.Name] = ((IProperty) instance).EvaluatedValueEscaped;
- }
- return ReadOnlyDictionary<string, string>.CreateWrapper(backing);
- }
- }
-
- internal PropertyDictionary<ProjectPropertyInstance> GlobalPropertiesDictionary
- {
- [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.globalProperties;
- }
- }
-
- internal IDictionary<string, object> InitialGlobalsForDebugging
- {
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.initialGlobalsForDebugging;
- }
- }
-
- public List<string> InitialTargets
- {
- [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- …
Large files files are truncated, but you can click here to view the full file