/Microsoft.Build/Microsoft.Build/Microsoft/Build/Construction/ProjectRootElement.cs
C# | 1088 lines | 985 code | 103 blank | 0 comment | 73 complexity | e9e48127a8294603a43a7f5513cfe351 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0
- namespace Microsoft.Build.Construction
- {
- using Microsoft.Build.BackEnd.Logging;
- using Microsoft.Build.Collections;
- using Microsoft.Build.Evaluation;
- using Microsoft.Build.Exceptions;
- using Microsoft.Build.Framework;
- using Microsoft.Build.Internal;
- using Microsoft.Build.Shared;
- using Microsoft.Internal.Performance;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Globalization;
- using System.IO;
- using System.Runtime;
- using System.Runtime.CompilerServices;
- using System.Text;
- using System.Threading;
- using System.Xml;
-
- [DebuggerDisplay("{FullPath} #Children={Count} DefaultTargets={DefaultTargets} ToolsVersion={ToolsVersion} InitialTargets={InitialTargets}")]
- public class ProjectRootElement : ProjectElementContainer
- {
- private BuildEventContext buildEventContext;
- private static readonly System.Text.Encoding DefaultEncoding = System.Text.Encoding.UTF8;
- private string directory;
- private string dirtyParameter;
- private string dirtyReason;
- private const string EmptyProjectFileContent = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n</Project>";
- private System.Text.Encoding encoding;
- private static int globalVersionCounter = 0;
- private DateTime lastWriteTimeWhenRead;
- private RenameHandlerDelegate OnAfterProjectRename;
- private ElementLocation projectFileLocation;
- private Microsoft.Build.Evaluation.ProjectRootElementCache projectRootElementCache;
- private DateTime timeLastChangedUtc;
- private int version;
- private int versionOnDisk;
-
- internal event RenameHandlerDelegate OnAfterProjectRename
- {
- add
- {
- RenameHandlerDelegate delegate3;
- RenameHandlerDelegate onAfterProjectRename = this.OnAfterProjectRename;
- do
- {
- delegate3 = onAfterProjectRename;
- RenameHandlerDelegate delegate4 = (RenameHandlerDelegate) Delegate.Combine(delegate3, value);
- onAfterProjectRename = Interlocked.CompareExchange<RenameHandlerDelegate>(ref this.OnAfterProjectRename, delegate4, delegate3);
- }
- while (onAfterProjectRename != delegate3);
- }
- remove
- {
- RenameHandlerDelegate delegate3;
- RenameHandlerDelegate onAfterProjectRename = this.OnAfterProjectRename;
- do
- {
- delegate3 = onAfterProjectRename;
- RenameHandlerDelegate delegate4 = (RenameHandlerDelegate) Delegate.Remove(delegate3, value);
- onAfterProjectRename = Interlocked.CompareExchange<RenameHandlerDelegate>(ref this.OnAfterProjectRename, delegate4, delegate3);
- }
- while (onAfterProjectRename != delegate3);
- }
- }
-
- private ProjectRootElement(Microsoft.Build.Evaluation.ProjectRootElementCache projectRootElementCache)
- {
- this.dirtyReason = "first created project {0}";
- this.dirtyParameter = string.Empty;
- ErrorUtilities.VerifyThrowArgumentNull(projectRootElementCache, "projectRootElementCache");
- this.projectRootElementCache = projectRootElementCache;
- this.directory = NativeMethodsShared.GetCurrentDirectory();
- this.IncrementVersion();
- XmlDocumentWithLocation document = new XmlDocumentWithLocation();
- document.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n</Project>");
- ProjectParser.Parse(document, this);
- }
-
- private ProjectRootElement(XmlDocumentWithLocation document, Microsoft.Build.Evaluation.ProjectRootElementCache projectRootElementCache)
- {
- this.dirtyReason = "first created project {0}";
- this.dirtyParameter = string.Empty;
- ErrorUtilities.VerifyThrowArgumentNull(document, "document");
- ErrorUtilities.VerifyThrowArgumentNull(projectRootElementCache, "projectRootElementCache");
- this.projectRootElementCache = projectRootElementCache;
- this.directory = NativeMethodsShared.GetCurrentDirectory();
- this.IncrementVersion();
- ProjectParser.Parse(document, this);
- }
-
- internal ProjectRootElement(XmlReader xmlReader, Microsoft.Build.Evaluation.ProjectRootElementCache projectRootElementCache)
- {
- this.dirtyReason = "first created project {0}";
- this.dirtyParameter = string.Empty;
- ErrorUtilities.VerifyThrowArgumentNull(xmlReader, "xmlReader");
- ErrorUtilities.VerifyThrowArgumentNull(projectRootElementCache, "projectRootElementCache");
- this.projectRootElementCache = projectRootElementCache;
- this.directory = NativeMethodsShared.GetCurrentDirectory();
- this.IncrementVersion();
- ProjectParser.Parse(this.LoadDocument(xmlReader), this);
- }
-
- private ProjectRootElement(string path, Microsoft.Build.Evaluation.ProjectRootElementCache projectRootElementCache, BuildEventContext buildEventContext)
- {
- this.dirtyReason = "first created project {0}";
- this.dirtyParameter = string.Empty;
- ErrorUtilities.VerifyThrowArgumentLength(path, "path");
- ErrorUtilities.VerifyThrowInternalRooted(path);
- ErrorUtilities.VerifyThrowArgumentNull(projectRootElementCache, "projectRootElementCache");
- ErrorUtilities.VerifyThrowArgumentNull(buildEventContext, "buildEventContext");
- this.projectRootElementCache = projectRootElementCache;
- this.buildEventContext = buildEventContext;
- this.IncrementVersion();
- this.versionOnDisk = this.version;
- this.timeLastChangedUtc = DateTime.UtcNow;
- ProjectParser.Parse(this.LoadDocument(path), this);
- projectRootElementCache.AddEntry(this);
- }
-
- public ProjectImportElement AddImport(string project)
- {
- ErrorUtilities.VerifyThrowArgumentLength(project, "project");
- ProjectImportGroupElement element = null;
- foreach (ProjectImportGroupElement element2 in this.ImportGroupsReversed)
- {
- if (element2.Condition.Length <= 0)
- {
- element = element2;
- break;
- }
- }
- if (element != null)
- {
- return element.AddImport(project);
- }
- ProjectImportElement child = this.CreateImportElement(project);
- base.AppendChild(child);
- return child;
- }
-
- public ProjectImportGroupElement AddImportGroup()
- {
- ProjectImportGroupElement child = this.CreateImportGroupElement();
- base.AppendChild(child);
- return child;
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public ProjectItemElement AddItem(string itemType, string include)
- {
- return this.AddItem(itemType, include, null);
- }
-
- public ProjectItemElement AddItem(string itemType, string include, IEnumerable<KeyValuePair<string, string>> metadata)
- {
- ErrorUtilities.VerifyThrowArgumentLength(itemType, "itemType");
- ErrorUtilities.VerifyThrowArgumentLength(include, "include");
- ProjectItemGroupElement element = null;
- foreach (ProjectItemGroupElement element2 in this.ItemGroups)
- {
- if (element2.Condition.Length > 0)
- {
- continue;
- }
- if ((element == null) && (element2.Count == 0))
- {
- element = element2;
- }
- foreach (ProjectItemElement element3 in element2.Items)
- {
- if (MSBuildNameIgnoreCaseComparer.Default.Equals(itemType, element3.ItemType))
- {
- element = element2;
- break;
- }
- }
- if ((element != null) && (element.Count > 0))
- {
- break;
- }
- }
- if (element == null)
- {
- element = this.AddItemGroup();
- }
- return element.AddItem(itemType, include, metadata);
- }
-
- public ProjectItemDefinitionElement AddItemDefinition(string itemType)
- {
- ErrorUtilities.VerifyThrowArgumentLength(itemType, "itemType");
- ProjectItemDefinitionGroupElement element = null;
- foreach (ProjectItemDefinitionGroupElement element2 in this.ItemDefinitionGroups)
- {
- if (element2.Condition.Length > 0)
- {
- continue;
- }
- foreach (ProjectItemDefinitionElement element3 in element2.ItemDefinitions)
- {
- if (MSBuildNameIgnoreCaseComparer.Default.Equals(itemType, element3.ItemType))
- {
- element = element2;
- break;
- }
- }
- if (element != null)
- {
- break;
- }
- }
- if (element == null)
- {
- element = this.AddItemDefinitionGroup();
- }
- ProjectItemDefinitionElement child = this.CreateItemDefinitionElement(itemType);
- element.AppendChild(child);
- return child;
- }
-
- public ProjectItemDefinitionGroupElement AddItemDefinitionGroup()
- {
- ProjectElement reference = null;
- foreach (ProjectItemDefinitionGroupElement element2 in this.ItemDefinitionGroupsReversed)
- {
- reference = element2;
- break;
- }
- if (reference == null)
- {
- foreach (ProjectPropertyGroupElement element3 in this.PropertyGroupsReversed)
- {
- reference = element3;
- break;
- }
- }
- ProjectItemDefinitionGroupElement child = this.CreateItemDefinitionGroupElement();
- base.InsertAfterChild(child, reference);
- return child;
- }
-
- public ProjectItemGroupElement AddItemGroup()
- {
- ProjectElement reference = null;
- foreach (ProjectItemGroupElement element2 in this.ItemGroupsReversed)
- {
- reference = element2;
- break;
- }
- if (reference == null)
- {
- foreach (ProjectPropertyGroupElement element3 in this.PropertyGroupsReversed)
- {
- reference = element3;
- break;
- }
- }
- ProjectItemGroupElement child = this.CreateItemGroupElement();
- if (reference == null)
- {
- base.AppendChild(child);
- return child;
- }
- base.InsertAfterChild(child, reference);
- return child;
- }
-
- public ProjectPropertyElement AddProperty(string name, string value)
- {
- ProjectPropertyGroupElement element = null;
- ProjectPropertyElement element2 = null;
- foreach (ProjectPropertyGroupElement element3 in this.PropertyGroups)
- {
- if (element3.Condition.Length <= 0)
- {
- if (element == null)
- {
- element = element3;
- }
- foreach (ProjectPropertyElement element4 in element3.Properties)
- {
- if ((element4.Condition.Length <= 0) && MSBuildNameIgnoreCaseComparer.Default.Equals(element4.Name, name))
- {
- element2 = element4;
- }
- }
- continue;
- }
- }
- if (element2 != null)
- {
- element2.Value = value;
- return element2;
- }
- if (element == null)
- {
- element = this.AddPropertyGroup();
- }
- return element.AddProperty(name, value);
- }
-
- public ProjectPropertyGroupElement AddPropertyGroup()
- {
- ProjectPropertyGroupElement reference = null;
- foreach (ProjectPropertyGroupElement element2 in this.PropertyGroupsReversed)
- {
- reference = element2;
- break;
- }
- ProjectPropertyGroupElement child = this.CreatePropertyGroupElement();
- base.InsertAfterChild(child, reference);
- return child;
- }
-
- public ProjectTargetElement AddTarget(string name)
- {
- ProjectTargetElement child = this.CreateTargetElement(name);
- base.AppendChild(child);
- return child;
- }
-
- public ProjectUsingTaskElement AddUsingTask(string name, string assemblyFile, string assemblyName)
- {
- ProjectUsingTaskElement child = this.CreateUsingTaskElement(name, assemblyFile, assemblyName);
- base.AppendChild(child);
- return child;
- }
-
- public static ProjectRootElement Create()
- {
- return Create(ProjectCollection.GlobalProjectCollection);
- }
-
- public static ProjectRootElement Create(ProjectCollection projectCollection)
- {
- ErrorUtilities.VerifyThrowArgumentNull(projectCollection, "projectCollection");
- return Create(projectCollection.ProjectRootElementCache);
- }
-
- internal static ProjectRootElement Create(Microsoft.Build.Evaluation.ProjectRootElementCache projectRootElementCache)
- {
- return new ProjectRootElement(projectRootElementCache);
- }
-
- public static ProjectRootElement Create(string path)
- {
- return Create(path, ProjectCollection.GlobalProjectCollection);
- }
-
- public static ProjectRootElement Create(XmlReader xmlReader)
- {
- return Create(xmlReader, ProjectCollection.GlobalProjectCollection);
- }
-
- public static ProjectRootElement Create(string path, ProjectCollection projectCollection)
- {
- ErrorUtilities.VerifyThrowArgumentLength(path, "path");
- ErrorUtilities.VerifyThrowArgumentNull(projectCollection, "projectCollection");
- return new ProjectRootElement(projectCollection.ProjectRootElementCache) { FullPath = path };
- }
-
- public static ProjectRootElement Create(XmlReader xmlReader, ProjectCollection projectCollection)
- {
- ErrorUtilities.VerifyThrowArgumentNull(projectCollection, "projectCollection");
- return new ProjectRootElement(xmlReader, projectCollection.ProjectRootElementCache);
- }
-
- public ProjectChooseElement CreateChooseElement()
- {
- return ProjectChooseElement.CreateDisconnected(this);
- }
-
- internal XmlElementWithLocation CreateElement(string name)
- {
- return (XmlElementWithLocation) base.XmlDocument.CreateElement(name, "http://schemas.microsoft.com/developer/msbuild/2003");
- }
-
- public ProjectImportElement CreateImportElement(string project)
- {
- return ProjectImportElement.CreateDisconnected(project, this);
- }
-
- public ProjectImportGroupElement CreateImportGroupElement()
- {
- return ProjectImportGroupElement.CreateDisconnected(this);
- }
-
- public ProjectItemDefinitionElement CreateItemDefinitionElement(string itemType)
- {
- return ProjectItemDefinitionElement.CreateDisconnected(itemType, this);
- }
-
- public ProjectItemDefinitionGroupElement CreateItemDefinitionGroupElement()
- {
- return ProjectItemDefinitionGroupElement.CreateDisconnected(this);
- }
-
- public ProjectItemElement CreateItemElement(string itemType)
- {
- return ProjectItemElement.CreateDisconnected(itemType, this);
- }
-
- public ProjectItemElement CreateItemElement(string itemType, string include)
- {
- ProjectItemElement element = ProjectItemElement.CreateDisconnected(itemType, this);
- element.Include = include;
- return element;
- }
-
- public ProjectItemGroupElement CreateItemGroupElement()
- {
- return ProjectItemGroupElement.CreateDisconnected(this);
- }
-
- public ProjectMetadataElement CreateMetadataElement(string name)
- {
- return ProjectMetadataElement.CreateDisconnected(name, this);
- }
-
- public ProjectMetadataElement CreateMetadataElement(string name, string unevaluatedValue)
- {
- ProjectMetadataElement element = ProjectMetadataElement.CreateDisconnected(name, this);
- element.Value = unevaluatedValue;
- return element;
- }
-
- public ProjectOnErrorElement CreateOnErrorElement(string executeTargets)
- {
- return ProjectOnErrorElement.CreateDisconnected(executeTargets, this);
- }
-
- public ProjectOtherwiseElement CreateOtherwiseElement()
- {
- return ProjectOtherwiseElement.CreateDisconnected(this);
- }
-
- public ProjectOutputElement CreateOutputElement(string taskParameter, string itemType, string propertyName)
- {
- return ProjectOutputElement.CreateDisconnected(taskParameter, itemType, propertyName, this);
- }
-
- public ProjectExtensionsElement CreateProjectExtensionsElement()
- {
- return ProjectExtensionsElement.CreateDisconnected(this);
- }
-
- private static ProjectRootElement CreateProjectFromPath(string projectFile, IDictionary<string, string> globalProperties, string toolsVersion, ILoggingService loggingService, Microsoft.Build.Evaluation.ProjectRootElementCache projectRootElementCache, BuildEventContext buildEventContext)
- {
- ProjectRootElement element;
- ErrorUtilities.VerifyThrowInternalRooted(projectFile);
- try
- {
- if (FileUtilities.IsVCProjFilename(projectFile))
- {
- ProjectFileErrorUtilities.ThrowInvalidProjectFile(new BuildEventFileInfo(projectFile), "ProjectUpgradeNeededToVcxProj", new object[] { projectFile });
- }
- element = new ProjectRootElement(projectFile, projectRootElementCache, buildEventContext);
- }
- catch (InvalidProjectFileException)
- {
- throw;
- }
- catch (Exception exception)
- {
- if (!ExceptionHandling.NotExpectedException(exception))
- {
- ProjectFileErrorUtilities.ThrowInvalidProjectFile(new BuildEventFileInfo(projectFile), exception, "InvalidProjectFile", new object[] { exception.Message });
- }
- throw;
- }
- return element;
- }
-
- public ProjectPropertyElement CreatePropertyElement(string name)
- {
- return ProjectPropertyElement.CreateDisconnected(name, this);
- }
-
- public ProjectPropertyGroupElement CreatePropertyGroupElement()
- {
- return ProjectPropertyGroupElement.CreateDisconnected(this);
- }
-
- public ProjectTargetElement CreateTargetElement(string name)
- {
- return ProjectTargetElement.CreateDisconnected(name, this);
- }
-
- public ProjectTaskElement CreateTaskElement(string name)
- {
- return ProjectTaskElement.CreateDisconnected(name, this);
- }
-
- public ProjectUsingTaskBodyElement CreateUsingTaskBodyElement(string evaluate, string body)
- {
- return ProjectUsingTaskBodyElement.CreateDisconnected(evaluate, body, this);
- }
-
- public ProjectUsingTaskElement CreateUsingTaskElement(string taskName, string assemblyFile, string assemblyName)
- {
- return ProjectUsingTaskElement.CreateDisconnected(taskName, assemblyFile, assemblyName, this);
- }
-
- public ProjectUsingTaskParameterElement CreateUsingTaskParameterElement(string name, string output, string required, string parameterType)
- {
- return ProjectUsingTaskParameterElement.CreateDisconnected(name, output, required, parameterType, this);
- }
-
- public UsingTaskParameterGroupElement CreateUsingTaskParameterGroupElement()
- {
- return UsingTaskParameterGroupElement.CreateDisconnected(this);
- }
-
- public ProjectWhenElement CreateWhenElement(string condition)
- {
- return ProjectWhenElement.CreateDisconnected(condition, this);
- }
-
- private void IncrementVersion()
- {
- this.version = Interlocked.Increment(ref globalVersionCounter);
- }
-
- private XmlDocumentWithLocation LoadDocument(string fullPath)
- {
- ErrorUtilities.VerifyThrowInternalRooted(fullPath);
- XmlDocumentWithLocation location = new XmlDocumentWithLocation();
- Microsoft.Internal.Performance.CodeMarkerStartEnd end = new Microsoft.Internal.Performance.CodeMarkerStartEnd(Microsoft.Internal.Performance.CodeMarkerEvent.perfMSBuildProjectLoadFromFileBegin, Microsoft.Internal.Performance.CodeMarkerEvent.perfMSBuildProjectLoadFromFileEnd);
- try
- {
- using (XmlTextReader reader = new XmlTextReader(fullPath))
- {
- reader.Read();
- this.encoding = reader.Encoding;
- location.Load(reader);
- }
- location.FullPath = fullPath;
- this.projectFileLocation = new ElementLocation(fullPath);
- this.directory = Path.GetDirectoryName(fullPath);
- if (base.XmlDocument != null)
- {
- base.XmlDocument.FullPath = fullPath;
- }
- this.lastWriteTimeWhenRead = FileUtilities.GetFileInfoNoThrow(fullPath).LastWriteTime;
- }
- catch (Exception exception)
- {
- BuildEventFileInfo info;
- if (ExceptionHandling.NotExpectedIoOrXmlException(exception))
- {
- throw;
- }
- XmlException e = exception as XmlException;
- if (e != null)
- {
- info = new BuildEventFileInfo(e);
- }
- else
- {
- info = new BuildEventFileInfo(fullPath);
- }
- ProjectFileErrorUtilities.ThrowInvalidProjectFile(info, exception, "InvalidProjectFile", new object[] { exception.Message });
- }
- finally
- {
- if (end != null)
- {
- end.Dispose();
- }
- }
- return location;
- }
-
- private XmlDocumentWithLocation LoadDocument(XmlReader reader)
- {
- XmlDocumentWithLocation location = new XmlDocumentWithLocation();
- try
- {
- location.Load(reader);
- }
- catch (XmlException exception)
- {
- BuildEventFileInfo projectFile = new BuildEventFileInfo(exception);
- ProjectFileErrorUtilities.ThrowInvalidProjectFile(projectFile, "InvalidProjectFile", new object[] { exception.Message });
- }
- return location;
- }
-
- internal sealed override void MarkDirty(string reason, string param)
- {
- this.IncrementVersion();
- this.dirtyReason = reason;
- this.dirtyParameter = param;
- this.timeLastChangedUtc = DateTime.UtcNow;
- }
-
- internal static ProjectRootElement Open(XmlDocumentWithLocation document)
- {
- ErrorUtilities.VerifyThrow(document.FullPath == null, "Only virtual documents supported");
- return new ProjectRootElement(document, ProjectCollection.GlobalProjectCollection.ProjectRootElementCache);
- }
-
- public static ProjectRootElement Open(string path)
- {
- return Open(path, ProjectCollection.GlobalProjectCollection);
- }
-
- public static ProjectRootElement Open(string path, ProjectCollection projectCollection)
- {
- ErrorUtilities.VerifyThrowArgumentLength(path, "path");
- ErrorUtilities.VerifyThrowArgumentNull(projectCollection, "projectCollection");
- path = FileUtilities.NormalizePath(path);
- return Open(path, projectCollection.ProjectRootElementCache);
- }
-
- internal static ProjectRootElement Open(string path, Microsoft.Build.Evaluation.ProjectRootElementCache projectRootElementCache)
- {
- ErrorUtilities.VerifyThrowInternalRooted(path);
- return projectRootElementCache.Get(path, () => new ProjectRootElement(path, projectRootElementCache, new BuildEventContext(0, -2, -2, -1)));
- }
-
- internal static ProjectRootElement OpenProjectOrSolution(string fullPath, IDictionary<string, string> globalProperties, string toolsVersion, ILoggingService loggingService, Microsoft.Build.Evaluation.ProjectRootElementCache projectRootElementCache, BuildEventContext buildEventContext)
- {
- ErrorUtilities.VerifyThrowInternalRooted(fullPath);
- return projectRootElementCache.Get(fullPath, () => CreateProjectFromPath(fullPath, globalProperties, toolsVersion, loggingService, projectRootElementCache, buildEventContext));
- }
-
- public void Save()
- {
- this.Save(this.Encoding);
- }
-
- public void Save(TextWriter writer)
- {
- using (ProjectWriter writer2 = new ProjectWriter(writer))
- {
- writer2.Initialize(base.XmlDocument);
- base.XmlDocument.Save(writer2);
- }
- this.versionOnDisk = this.Version;
- }
-
- public void Save(string path)
- {
- this.Save(path, this.Encoding);
- }
-
- public void Save(System.Text.Encoding saveEncoding)
- {
- ErrorUtilities.VerifyThrowInvalidOperation(this.projectFileLocation != null, "OM_MustSetFileNameBeforeSave");
- Directory.CreateDirectory(this.DirectoryPath);
- using (new Microsoft.Internal.Performance.CodeMarkerStartEnd(Microsoft.Internal.Performance.CodeMarkerEvent.perfMSBuildProjectSaveToFileBegin, Microsoft.Internal.Performance.CodeMarkerEvent.perfMSBuildProjectSaveToFileEnd))
- {
- if (this.HasUnsavedChanges || (saveEncoding != this.Encoding))
- {
- using (ProjectWriter writer = new ProjectWriter(this.projectFileLocation.File, saveEncoding))
- {
- writer.Initialize(base.XmlDocument);
- base.XmlDocument.Save(writer);
- }
- this.encoding = saveEncoding;
- this.lastWriteTimeWhenRead = FileUtilities.GetFileInfoNoThrow(this.projectFileLocation.File).LastWriteTime;
- this.versionOnDisk = this.Version;
- }
- }
- }
-
- public void Save(string path, System.Text.Encoding encoding)
- {
- this.FullPath = path;
- this.Save(encoding);
- }
-
- public static ProjectRootElement TryOpen(string path)
- {
- ErrorUtilities.VerifyThrowArgumentLength(path, "path");
- return TryOpen(path, ProjectCollection.GlobalProjectCollection);
- }
-
- public static ProjectRootElement TryOpen(string path, ProjectCollection projectCollection)
- {
- ErrorUtilities.VerifyThrowArgumentLength(path, "path");
- ErrorUtilities.VerifyThrowArgumentNull(projectCollection, "projectCollection");
- path = FileUtilities.NormalizePath(path);
- return projectCollection.ProjectRootElementCache.TryGet(path);
- }
-
- internal override void VerifyThrowInvalidOperationAcceptableLocation(ProjectElementContainer parent, ProjectElement previousSibling, ProjectElement nextSibling)
- {
- ErrorUtilities.ThrowInvalidOperation("OM_CannotAcceptParent", new object[0]);
- }
-
- public ICollection<ProjectChooseElement> ChooseElements
- {
- get
- {
- return new ReadOnlyCollection<ProjectChooseElement>(new FilteringEnumerable<ProjectElement, ProjectChooseElement>(base.Children));
- }
- }
-
- public override string Condition
- {
- get
- {
- return null;
- }
- set
- {
- ErrorUtilities.ThrowInvalidOperation("OM_CannotGetSetCondition", new object[0]);
- }
- }
-
- internal override IElementLocation ConditionLocation
- {
- get
- {
- ErrorUtilities.ThrowInternalError("Should not evaluate this", new object[0]);
- return null;
- }
- }
-
- internal bool ContainsTargetsWithReturnsAttribute
- {
- [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.<ContainsTargetsWithReturnsAttribute>k__BackingField;
- }
- [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- set
- {
- this.<ContainsTargetsWithReturnsAttribute>k__BackingField = value;
- }
- }
-
- public string DefaultTargets
- {
- [DebuggerStepThrough]
- get
- {
- return ProjectXmlUtilities.GetAttributeValue(base.XmlElement, "DefaultTargets");
- }
- [DebuggerStepThrough]
- set
- {
- ProjectXmlUtilities.SetOrRemoveAttribute(base.XmlElement, "DefaultTargets", value);
- this.MarkDirty("Set Project DefaultTargets to '{0}'", value);
- }
- }
-
- internal IElementLocation DefaultTargetsLocation
- {
- get
- {
- return base.XmlElement.GetAttributeLocation("DefaultTargets");
- }
- }
-
- public string DirectoryPath
- {
- [DebuggerStepThrough]
- get
- {
- return (this.directory ?? string.Empty);
- }
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- internal set
- {
- this.directory = value;
- }
- }
-
- public System.Text.Encoding Encoding
- {
- get
- {
- if (this.encoding == null)
- {
- XmlDeclaration firstChild = base.XmlDocument.FirstChild as XmlDeclaration;
- if ((firstChild != null) && (firstChild.Encoding.Length > 0))
- {
- this.encoding = System.Text.Encoding.GetEncoding(firstChild.Encoding);
- }
- }
- return (this.encoding ?? DefaultEncoding);
- }
- }
-
- public string FullPath
- {
- get
- {
- if (this.projectFileLocation == null)
- {
- return null;
- }
- return this.projectFileLocation.File;
- }
- set
- {
- ErrorUtilities.VerifyThrowArgumentLength(value, "value");
- string a = (this.projectFileLocation != null) ? this.projectFileLocation.File : null;
- string b = FileUtilities.NormalizePath(value);
- if (!string.Equals(a, b, StringComparison.OrdinalIgnoreCase))
- {
- this.projectFileLocation = new ElementLocation(b);
- this.directory = Path.GetDirectoryName(b);
- if (base.XmlDocument != null)
- {
- base.XmlDocument.FullPath = b;
- }
- if (a == null)
- {
- this.projectRootElementCache.AddEntry(this);
- }
- else
- {
- this.projectRootElementCache.RenameEntry(a, this);
- }
- RenameHandlerDelegate onAfterProjectRename = this.OnAfterProjectRename;
- if (onAfterProjectRename != null)
- {
- onAfterProjectRename(a);
- }
- this.MarkDirty("Set project FullPath to '{0}'", this.FullPath);
- }
- }
- }
-
- public bool HasUnsavedChanges
- {
- get
- {
- return (this.Version != this.versionOnDisk);
- }
- }
-
- public ICollection<ProjectImportGroupElement> ImportGroups
- {
- get
- {
- return new ReadOnlyCollection<ProjectImportGroupElement>(new FilteringEnumerable<ProjectElement, ProjectImportGroupElement>(base.Children));
- }
- }
-
- public ICollection<ProjectImportGroupElement> ImportGroupsReversed
- {
- get
- {
- return new ReadOnlyCollection<ProjectImportGroupElement>(new FilteringEnumerable<ProjectElement, ProjectImportGroupElement>(base.ChildrenReversed));
- }
- }
-
- public ICollection<ProjectImportElement> Imports
- {
- get
- {
- return new ReadOnlyCollection<ProjectImportElement>(new FilteringEnumerable<ProjectElement, ProjectImportElement>(base.AllChildren));
- }
- }
-
- public string InitialTargets
- {
- [DebuggerStepThrough]
- get
- {
- return ProjectXmlUtilities.GetAttributeValue(base.XmlElement, "InitialTargets");
- }
- [DebuggerStepThrough]
- set
- {
- ProjectXmlUtilities.SetOrRemoveAttribute(base.XmlElement, "InitialTargets", value);
- this.MarkDirty("Set project InitialTargets to '{0}'", value);
- }
- }
-
- internal IElementLocation InitialTargetsLocation
- {
- get
- {
- return base.XmlElement.GetAttributeLocation("InitialTargets");
- }
- }
-
- public ICollection<ProjectItemDefinitionGroupElement> ItemDefinitionGroups
- {
- get
- {
- return new ReadOnlyCollection<ProjectItemDefinitionGroupElement>(new FilteringEnumerable<ProjectElement, ProjectItemDefinitionGroupElement>(base.Children));
- }
- }
-
- public ICollection<ProjectItemDefinitionGroupElement> ItemDefinitionGroupsReversed
- {
- get
- {
- return new ReadOnlyCollection<ProjectItemDefinitionGroupElement>(new FilteringEnumerable<ProjectElement, ProjectItemDefinitionGroupElement>(base.ChildrenReversed));
- }
- }
-
- public ICollection<ProjectItemDefinitionElement> ItemDefinitions
- {
- get
- {
- return new ReadOnlyCollection<ProjectItemDefinitionElement>(new FilteringEnumerable<ProjectElement, ProjectItemDefinitionElement>(base.AllChildren));
- }
- }
-
- public ICollection<ProjectItemGroupElement> ItemGroups
- {
- get
- {
- return new ReadOnlyCollection<ProjectItemGroupElement>(new FilteringEnumerable<ProjectElement, ProjectItemGroupElement>(base.Children));
- }
- }
-
- public ICollection<ProjectItemGroupElement> ItemGroupsReversed
- {
- get
- {
- return new ReadOnlyCollection<ProjectItemGroupElement>(new FilteringEnumerable<ProjectElement, ProjectItemGroupElement>(base.ChildrenReversed));
- }
- }
-
- public ICollection<ProjectItemElement> Items
- {
- get
- {
- return new ReadOnlyCollection<ProjectItemElement>(new FilteringEnumerable<ProjectElement, ProjectItemElement>(base.AllChildren));
- }
- }
-
- internal string LastDirtyReason
- {
- get
- {
- if (this.dirtyReason == null)
- {
- return null;
- }
- return string.Format(CultureInfo.InvariantCulture, this.dirtyReason, new object[] { this.dirtyParameter });
- }
- }
-
- public DateTime LastWriteTimeWhenRead
- {
- [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.lastWriteTimeWhenRead;
- }
- }
-
- internal ProjectExtensionsElement ProjectExtensions
- {
- get
- {
- foreach (ProjectElement element in base.ChildrenReversed)
- {
- ProjectExtensionsElement element2 = element as ProjectExtensionsElement;
- if (element2 != null)
- {
- return element2;
- }
- }
- return null;
- }
- }
-
- internal IElementLocation ProjectFileLocation
- {
- get
- {
- return (this.projectFileLocation ?? ElementLocation.EmptyLocation);
- }
- }
-
- internal Microsoft.Build.Evaluation.ProjectRootElementCache ProjectRootElementCache
- {
- [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.projectRootElementCache;
- }
- }
-
- public ICollection<ProjectPropertyElement> Properties
- {
- get
- {
- return new ReadOnlyCollection<ProjectPropertyElement>(new FilteringEnumerable<ProjectElement, ProjectPropertyElement>(base.AllChildren));
- }
- }
-
- public ICollection<ProjectPropertyGroupElement> PropertyGroups
- {
- get
- {
- return new ReadOnlyCollection<ProjectPropertyGroupElement>(new FilteringEnumerable<ProjectElement, ProjectPropertyGroupElement>(base.Children));
- }
- }
-
- public ICollection<ProjectPropertyGroupElement> PropertyGroupsReversed
- {
- get
- {
- return new ReadOnlyCollection<ProjectPropertyGroupElement>(new FilteringEnumerable<ProjectElement, ProjectPropertyGroupElement>(base.ChildrenReversed));
- }
- }
-
- public string RawXml
- {
- get
- {
- using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture))
- {
- using (ProjectWriter writer2 = new ProjectWriter(writer))
- {
- writer2.Initialize(base.XmlDocument);
- base.XmlDocument.Save(writer2);
- }
- return writer.ToString();
- }
- }
- }
-
- public ICollection<ProjectTargetElement> Targets
- {
- get
- {
- return new ReadOnlyCollection<ProjectTargetElement>(new FilteringEnumerable<ProjectElement, ProjectTargetElement>(base.Children));
- }
- }
-
- public DateTime TimeLastChanged
- {
- [DebuggerStepThrough]
- get
- {
- return this.timeLastChangedUtc.ToLocalTime();
- }
- }
-
- public string ToolsVersion
- {
- [DebuggerStepThrough]
- get
- {
- return ProjectXmlUtilities.GetAttributeValue(base.XmlElement, "ToolsVersion");
- }
- [DebuggerStepThrough]
- set
- {
- ProjectXmlUtilities.SetOrRemoveAttribute(base.XmlElement, "ToolsVersion", value);
- this.MarkDirty("Set project ToolsVersion {0}", value);
- }
- }
-
- internal IElementLocation ToolsVersionLocation
- {
- get
- {
- return base.XmlElement.GetAttributeLocation("ToolsVersion");
- }
- }
-
- public ICollection<ProjectUsingTaskElement> UsingTasks
- {
- get
- {
- return new ReadOnlyCollection<ProjectUsingTaskElement>(new FilteringEnumerable<ProjectElement, ProjectUsingTaskElement>(base.Children));
- }
- }
-
- public int Version
- {
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.version;
- }
- }
- }
- }
-