Export (0) Print
Expand All

ProjectRootElement Class

Represents an MSBuild project, a targets file, or any other file that conforms to MSBuild project file schema. This class and its related classes allow a complete MSBuild project or targets file to be read and written.

Namespace:  Microsoft.Build.Construction
Assembly:  Microsoft.Build (in Microsoft.Build.dll)

[DebuggerDisplayAttribute("{FullPath} #Children={Count} DefaultTargets={DefaultTargets} ToolsVersion={ToolsVersion} InitialTargets={InitialTargets} ExplicitlyLoaded={IsExplicitlyLoaded}")]
public class ProjectRootElement : ProjectElementContainer

The ProjectRootElement type exposes the following members.

  NameDescription
Public propertyAllChildrenGets a recursive depth-first enumerator over all child elements. (Inherited from ProjectElementContainer.)
Public propertyAllParentsAll parent elements of this element, going up to the ProjectRootElement. None if this is a ProjectRootElement. None if this has not been attached to a parent yet. (Inherited from ProjectElement.)
Public propertyChildrenGets all child elements. (Inherited from ProjectElementContainer.)
Public propertyChildrenReversedGets all child elements, starting from the last child. (Inherited from ProjectElementContainer.)
Public propertyChooseElementsGets all child Choose Element (MSBuild) in this project.
Public propertyConditionGets null because the Condition attribute is nonexistent for this element and a nonexistent condition is implicitly true. (Overrides ProjectElement.Condition.)
Public propertyConditionLocationDo not use. The Condition attribute is nonexistent for ProjectRootElement. Get throws an internal error. (Overrides ProjectElement.ConditionLocation.)
Public propertyContainingProjectProjectRootElement (possibly imported) that contains this Xml. Cannot be null. (Inherited from ProjectElement.)
Public propertyCountGets the number of child elements. (Inherited from ProjectElementContainer.)
Public propertyDefaultTargetsGets or sets the value of the DefaultTargets attribute.
Public propertyDefaultTargetsLocationLocation of the DefaultTargets attribute on this element, if any.
Public propertyDirectoryPathGets the directory path to the project file.
Public propertyEncodingSpecifies the character encoding that the project file is to be saved in.
Public propertyFirstChildGets the first child element. (Inherited from ProjectElementContainer.)
Public propertyFullPathGets the full path to the project file.
Public propertyHasUnsavedChangesDetermines whether the project has been modified since it was last loaded or saved.
Public propertyImportGroupsGets all the child import groups in this project.
Public propertyImportGroupsReversedGets all the child import groups in this project, starting with the last group.
Public propertyImportsGets all the child import elements in this project.
Public propertyInitialTargetsGets or sets the value of the InitialTargets attribute.
Public propertyInitialTargetsLocationLocation of the InitialTargets attribute on this element, if any.
Public propertyItemDefinitionGroupsGets all the child item definition groups in this project.
Public propertyItemDefinitionGroupsReversedGets all the child item definition groups in this project, starting with the last group.
Public propertyItemDefinitionsGets all child item definitions in all item definition groups anywhere in this project.
Public propertyItemGroupsGets all the child item groups in this project.
Public propertyItemGroupsReversedGets all the child item groups present in this project, starting with the last group.
Public propertyItemsGets all child items in this project.
Public propertyLabelGets or sets the Label value. Returns empty string if it is not present. Removes the attribute if the value to set is empty. (Inherited from ProjectElement.)
Public propertyLabelLocationLocation of the "Label" attribute on this element, if any. If there is no such attribute, returns null; (Inherited from ProjectElement.)
Public propertyLastChildGets the last child element. (Inherited from ProjectElementContainer.)
Public propertyLastWriteTimeWhenReadGets the last-write-time of the project file.
Public propertyLocationLocation of the corresponding Xml element. May not be correct if file is not saved, or file has been edited since it was last saved. In the case of an unsaved edit, the location only contains the path to the file that the element originates from. (Inherited from ProjectElement.)
Public propertyNextSiblingNext sibling element. May be null. (Inherited from ProjectElement.)
Public propertyParentNull if this is a ProjectRootElement. Null if this has not been attached to a parent yet. (Inherited from ProjectElement.)
Public propertyPreviousSiblingPrevious sibling element. May be null. (Inherited from ProjectElement.)
Public propertyProjectFileLocationThe location of the originating file itself, not any specific content within it. If the file has not been given a name, this is an empty location. This is a legitimate case of having no location.
Public propertyPropertiesGets all the child properties in this project.
Public propertyPropertyGroupsGets all the child property groups in this project.
Public propertyPropertyGroupsReversedGets all the child property groups present in this project, starting with the last group.
Public propertyRawXmlGets the XML content that represents this project.
Public propertyTargetsGets all the child targets in this project.
Public propertyTimeLastChangedGets the time that this project was last modified.
Public propertyToolsVersionGets or sets the value of the ToolsVersion attribute.
Public propertyToolsVersionLocationThe location of the ToolsVersion attribute on this element, if any.
Public propertyTreatAsLocalPropertyGets or sets the value of the TreatAsLocalProperty attribute.
Public propertyTreatAsLocalPropertyLocationThe location of the TreatAsLocalProperty attribute on this element, if any.
Public propertyUsingTasksGets all child UsingTask Element (MSBuild) in this project.
Public propertyVersionGets the version number of this object.
Top

  NameDescription
Public methodAddImportAdds a project import to this project.
Public methodAddImportGroupCreates an import group at the end of this project.
Public methodAddItem(String, String)Adds an item to this project.
Public methodAddItem(String, String, IEnumerable<KeyValuePair<String, String>>)Adds an item with metadata to this project.
Public methodAddItemDefinitionAdds an item definition to this project.
Public methodAddItemDefinitionGroupAdds an item definition group to this project.
Public methodAddItemGroupCreates and adds an item group to this project.
Public methodAddPropertyUpdates or adds a property to this project.
Public methodAddPropertyGroupAdds a new property group to this project.
Public methodAddTargetAdds a target to the project.
Public methodAddUsingTaskAdds a UsingTask Element (MSBuild) to the project.
Public methodAppendChildAppends the child element as the last child of this project container. (Inherited from ProjectElementContainer.)
Public methodStatic memberCreate()Creates and initializes an in-memory, empty ProjectRootElement instance and adds it to the global project collection.
Public methodStatic memberCreate(ProjectCollection)Creates and initializes an in-memory, empty ProjectRootElement instance and adds it to the specified project collection.
Public methodStatic memberCreate(String)Creates and initializes an in-memory, empty ProjectRootElement instance and adds it to the global project collection. The new project root is initialized from data found at the specified file path.
Public methodStatic memberCreate(XmlReader)Creates and initializes an in-memory, empty ProjectRootElement instance and adds it to the global project collection. The new project root is initialized from data read from the specified XmlReader.
Public methodStatic memberCreate(String, ProjectCollection)Creates and initializes an in-memory, empty ProjectRootElement instance and adds it to the specified project collection. The new project root is initialized from data found at the specified file path.
Public methodStatic memberCreate(XmlReader, ProjectCollection)Creates and initializes an in-memory, empty ProjectRootElement instance and adds it to the specified project collection. The new project root is initialized from data read from the specified XmlReader.
Public methodCreateChooseElementCreates a Choose Element (MSBuild).
Public methodCreateImportElementCreates an Import Element (MSBuild).
Public methodCreateImportGroupElementCreates an import group.
Public methodCreateItemDefinitionElementCreates an item definition.
Public methodCreateItemDefinitionGroupElementCreates an item definition group.
Public methodCreateItemElement(String)Creates an item.
Public methodCreateItemElement(String, String)Creates an item with the specifed Include value.
Public methodCreateItemGroupElementCreates an item group.
Public methodCreateMetadataElement(String)Creates a metadata node with the specified name.
Public methodCreateMetadataElement(String, String)Creates a metadata node with the specified name and value.
Public methodCreateOnErrorElementCreates an OnError Element (MSBuild).
Public methodCreateOtherwiseElementCreates an Otherwise Element (MSBuild). Caller must add it to the location of choice in the project.
Public methodCreateOutputElementCreates an Output Element (MSBuild).
Public methodCreateProjectExtensionsElementCreates a ProjectExtensions Element (MSBuild).
Public methodCreatePropertyElementCreates a property.
Public methodCreatePropertyGroupElementCreates a property group.
Public methodCreateTargetElementCreates a target.
Public methodCreateTaskElementCreates a task.
Public methodCreateUsingTaskBodyElementCreates a task to be referenced by a UsingTask Element (MSBuild).
Public methodCreateUsingTaskElement(String, String, String)Adds a UsingTask Element (MSBuild) to the project.
Public methodCreateUsingTaskElement(String, String, String, String, String)Adds a UsingTask Element (MSBuild) to the project.
Public methodCreateUsingTaskParameterElementCreates a parameter for use in a UsingTask Element (MSBuild) parameter group.
Public methodCreateUsingTaskParameterGroupElementCreates a parameter group for a UsingTask Element (MSBuild).
Public methodCreateWhenElementCreates a When Element (MSBuild) with a specified Condition attribute.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInsertAfterChildInserts the child element after the reference element. (Inherited from ProjectElementContainer.)
Public methodInsertBeforeChildInserts the child element before the reference element. (Inherited from ProjectElementContainer.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodStatic memberOpen(String)Initializes a project root in the global project collection by loading data from the specified file path.
Public methodStatic memberOpen(String, ProjectCollection)Initializes a project root in the specified project collection by loading data from the specified file path.
Public methodPrependChildPrepends the child element as the first child of this project container. (Inherited from ProjectElementContainer.)
Public methodRemoveAllChildrenRemoves all the children, if any, from this project container. (Inherited from ProjectElementContainer.)
Public methodRemoveChildRemoves a child element from this project container. (Inherited from ProjectElementContainer.)
Public methodSave()Saves the project, if modified, to the file system.
Public methodSave(Encoding)Saves the project, if modified, using the specified character encoding.
Public methodSave(String)Saves the project, if modified or if the file path to storage has changed.
Public methodSave(TextWriter)Saves the project to the specified text writer, whether modified or not.
Public methodSave(String, Encoding)Saves the project, if modified or if the file path to storage has changed. Uses the specified character encoding..
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodStatic memberTryOpen(String)Gets the project root in the global project collection that was loaded into memory from the specified file path. or null if it is not currently in memory.
Public methodStatic memberTryOpen(String, ProjectCollection)Gets the project root in the specified project collection that was loaded into memory from the specified file path. or null if it is not currently in memory.
Top

Comments and white space cannot be edited through this model at present. Each project root element is associated with exactly one project collection. This allows the owner of that project collection to control its lifetime and not be surprised by edits that come from another project collection.

.NET Framework

Supported in: 4.6, 4.5, 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft