ProjectRootElement 类

定义

表示一个 MSBuild 项目、一个目标文件或任何其他符合 MSBuild 项目文件架构的文件。Represents an MSBuild project, a targets file, or any other file that conforms to MSBuild project file schema. 通过此类及其相关类,可以读写完整的 MSBuild 项目或目标文件。This class and its related classes allow a complete MSBuild project or targets file to be read and written.

public ref class ProjectRootElement : Microsoft::Build::Construction::ProjectElementContainer
public class ProjectRootElement : Microsoft.Build.Construction.ProjectElementContainer
type ProjectRootElement = class
    inherit ProjectElementContainer
Public Class ProjectRootElement
Inherits ProjectElementContainer
继承

注解

目前不能通过此模型编辑注释和空格。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.

属性

AllChildren

获取可枚举所有子元素的递归的深度优先的枚举器。Gets a recursive depth-first enumerator over all child elements.

(继承自 ProjectElementContainer)
AllParents

此元素的所有父元素(直至 ProjectRootElement)。All parent elements of this element, going up to the ProjectRootElement.

如果这是 ProjectRootElement,则 None。None if this is a ProjectRootElement.

如果还没有附加到一个父级,则没有。None if this has not been attached to a parent yet.

(继承自 ProjectElement)
Children

获取所有子元素。Gets all child elements.

(继承自 ProjectElementContainer)
ChildrenReversed

获取所有子元素(从最后一个子级开始)。Gets all child elements, starting from the last child.

(继承自 ProjectElementContainer)
ChooseElements

在此项目中获取所有子 Choose 元素 (MSBuild)Gets all child Choose Element (MSBuild) in this project.

Condition

始终返回 null,因为此元素的 Condition 特性不存在,而且不存在的条件隐式为 trueAlways returns null because the Condition attribute is nonexistent for this element, and a nonexistent condition is implicitly true.

ConditionLocation

请勿使用。Do not use. 条件特性为不存在的 ProjectRootElementThe Condition attribute is nonexistent for ProjectRootElement.

ContainingProject

包含该 XML 的 ProjectRootElement(可以导入) 。ProjectRootElement (possibly imported) that contains this Xml.

不能为 null。Cannot be null.

(继承自 ProjectElement)
Count

获取子元素的数量。Gets the number of child elements.

(继承自 ProjectElementContainer)
DefaultTargets

获取或设置 DefaultTargets 特性的值。Gets or sets the value of the DefaultTargets attribute.

DefaultTargetsLocation

此元素 DefaultTargets 特性的位置(如果有)。Location of the DefaultTargets attribute on this element, if any.

DirectoryPath

获取项目文件的目录路径。Gets the directory path to the project file.

Encoding

获取保存项目文件时将使用的字符编码。Gets the character encoding that the project file is to be saved in.

FirstChild

获取第一个子元素。Gets the first child element.

(继承自 ProjectElementContainer)
FullPath

获取项目文件的完整路径。Gets the full path to the project file.

HasUnsavedChanges

确定该项目自上一次加载或保存后是否已进行过修改。Determines whether the project has been modified since it was last loaded or saved.

ImportGroups

获取此项目中的所有子导入组。Gets all the child import groups in this project.

ImportGroupsReversed

获取此项目中的所有子导入组(从最后一个组开始)。Gets all the child import groups in this project, starting with the last group.

Imports

获取此项目中的所有子导入元素。Gets all the child import elements in this project.

InitialTargets

获取或设置 InitialTargets 特性的值。Gets or sets the value of the InitialTargets attribute.

InitialTargetsLocation

此元素 InitialTargets 特性的位置(如果有)。Location of the InitialTargets attribute on this element, if any.

ItemDefinitionGroups

获取此项目中的所有子项定义组。Gets all the child item definition groups in this project.

ItemDefinitionGroupsReversed

获取此项目中的所有子项定义组(从最后一个组开始)。Gets all the child item definition groups in this project, starting with the last group.

ItemDefinitions

获取此项目中所有项定义组中的所有子项定义。Gets all child item definitions in all item definition groups anywhere in this project.

ItemGroups

获取此项目中的所有子项组。Gets all the child item groups in this project.

ItemGroupsReversed

获取此项目中存在的所有子项组(从最后一个组开始)。Gets all the child item groups present in this project, starting with the last group.

Items

获取此项目中的所有子项。Gets all child items in this project.

Label

获取或设置 Label 值。Gets or sets the Label value.

如果该特性不存在,则返回空字符串。Returns empty string if it is not present.

如果要设置的值为空,则移除该特性。Removes the attribute if the value to set is empty.

(继承自 ProjectElement)
LabelLocation

此元素“标签”特性的位置(如果有)。Location of the "Label" attribute on this element, if any.

如果没有这样的属性,则返回 null。If there is no such attribute, returns null;

(继承自 ProjectElement)
LastChild

获取最后一个子元素。Gets the last child element.

(继承自 ProjectElementContainer)
LastWriteTimeWhenRead

获取项目文件的上次写入时间。Gets the last-write-time of the project file.

Location

对应的 Xml 元素的位置。Location 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.

(继承自 ProjectElement)
NextSibling

下一个同级元素。Next sibling element.

可能为 null。May be null.

(继承自 ProjectElement)
Parent

如果是 ProjectRootElement,则为 null。Null if this is a ProjectRootElement.

如果还没有附加到一个父级,则为 Null。Null if this has not been attached to a parent yet.

(继承自 ProjectElement)
PreviousSibling

上一个同级元素。Previous sibling element.

可能为 null。May be null.

(继承自 ProjectElement)
ProjectFileLocation

获取原始文件的位置,其中没有任何特定内容。Gets the 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.

Properties

获取此项目中的所有子属性。Gets all the child properties in this project.

PropertyGroups

获取此项目中的所有子属性组。Gets all the child property groups in this project.

PropertyGroupsReversed

获取此项目中存在的所有子属性组(从最后一个组开始)。Gets all the child property groups present in this project, starting with the last group.

RawXml

获取表示此项目的 XML 内容。Gets the XML content that represents this project.

Targets

获取此项目中的所有子目标。Gets all the child targets in this project.

TimeLastChanged

获取上次修改此项目的时间。Gets the time that this project was last modified.

ToolsVersion

获取或设置 ToolsVersion 特性的值。Gets or sets the value of the ToolsVersion attribute.

ToolsVersionLocation

获取此元素上 ToolsVersion 特性的位置(如有)。Gets the location of the ToolsVersion attribute on this element, if any.

TreatAsLocalProperty

获取或设置 TreatAsLocalProperty 特性的值。Gets or sets the value of the TreatAsLocalProperty attribute.

TreatAsLocalPropertyLocation

获取此元素上 TreatAsLocalProperty 特性的位置(如有)。Gets the location of the TreatAsLocalProperty attribute on this element, if any.

UsingTasks

在此项目中获取所有子 UsingTask 元素 (MSBuild)Gets all child UsingTask Element (MSBuild) in this project.

Version

获取此对象的版本号。Gets the version number of this object.

方法

AddImport(String)

向此项目中添加一个项目导入。Adds a project import to this project.

AddImportGroup()

在此项目的末尾创建一个导入组。Creates an import group at the end of this project.

AddItem(String, String)

向此项目中添加项。Adds an item to this project.

AddItem(String, String, IEnumerable<KeyValuePair<String,String>>)

向此项目中添加包含元数据的项。Adds an item with metadata to this project.

AddItemDefinition(String)

向此项目中添加项定义。Adds an item definition to this project.

AddItemDefinitionGroup()

向此项目中添加项定义组。Adds an item definition group to this project.

AddItemGroup()

创建一个项组并将其添加到此项目中。Creates and adds an item group to this project.

AddProperty(String, String)

在此项目中更新或添加属性。Updates or adds a property to this project.

AddPropertyGroup()

在此项目中添加新属性组。Adds a new property group to this project.

AddTarget(String)

向项目中添加目标。Adds a target to the project.

AddUsingTask(String, String, String)

UsingTask 元素 (MSBuild) 添加到项目。Adds a UsingTask Element (MSBuild) to the project.

AppendChild(ProjectElement)

child 元素追加为此项目容器的最后一个子级。Appends the child element as the last child of this project container.

(继承自 ProjectElementContainer)
Create()

创建并初始化一个内存中的空 ProjectRootElement 实例,并将其添加到全局项目集合中。Creates and initializes an in-memory, empty ProjectRootElement instance and adds it to the global project collection.

Create(ProjectCollection)

创建并初始化一个内存中的空 ProjectRootElement 实例,并将其添加到指定的项目集合中。Creates and initializes an in-memory, empty ProjectRootElement instance and adds it to the specified project collection.

Create(String)

创建并初始化一个内存中的空 ProjectRootElement 实例,并将其添加到全局项目集合中。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.

Create(String, ProjectCollection)

创建并初始化一个内存中的空 ProjectRootElement 实例,并将其添加到指定的项目集合中。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.

Create(XmlReader)

创建并初始化一个内存中的空 ProjectRootElement 实例,并将其添加到全局项目集合中。Creates and initializes an in-memory, empty ProjectRootElement instance and adds it to the global project collection. 利用从指定 XmlReader 读取的数据初始化新的项目根。The new project root is initialized from data read from the specified XmlReader.

Create(XmlReader, ProjectCollection)

创建并初始化一个内存中的空 ProjectRootElement 实例,并将其添加到指定的项目集合中。Creates and initializes an in-memory, empty ProjectRootElement instance and adds it to the specified project collection. 利用从指定 XmlReader 读取的数据初始化新的项目根。The new project root is initialized from data read from the specified XmlReader.

CreateChooseElement()

创建 Choose Element (MSBuild)Creates a Choose Element (MSBuild).

CreateImportElement(String)

创建 Import 元素 (MSBuild)Creates an Import Element (MSBuild).

CreateImportGroupElement()

创建一个导入组。Creates an import group.

CreateItemDefinitionElement(String)

创建一个项定义。Creates an item definition.

CreateItemDefinitionGroupElement()

创建一个项定义组。Creates an item definition group.

CreateItemElement(String)

创建一个项。Creates an item.

CreateItemElement(String, String)

创建包含指定 Include 值的项。Creates an item with the specified Include value.

CreateItemGroupElement()

创建一个项组。Creates an item group.

CreateMetadataElement(String)

创建一个具有指定名称的元数据节点。Creates a metadata node with the specified name.

CreateMetadataElement(String, String)

创建一个具有指定名称和值的元数据节点。Creates a metadata node with the specified name and value.

CreateOnErrorElement(String)

创建 OnError 元素 (MSBuild)Creates an OnError Element (MSBuild).

CreateOtherwiseElement()

创建 Otherwise 元素 (MSBuild)Creates an Otherwise Element (MSBuild). 调用方必须将其添加到项目中的选项位置。Caller must add it to the location of choice in the project.

CreateOutputElement(String, String, String)

创建 Output 元素 (MSBuild)Creates an Output Element (MSBuild).

CreateProjectExtensionsElement()

创建 ProjectExtensions 元素 (MSBuild)Creates a ProjectExtensions Element (MSBuild).

CreatePropertyElement(String)

创建一个属性。Creates a property.

CreatePropertyGroupElement()

创建一个属性组。Creates a property group.

CreateTargetElement(String)

创建一个目标。Creates a target.

CreateTaskElement(String)

创建任务。Creates a task.

CreateUsingTaskBodyElement(String, String)

创建由 UsingTask 元素 (MSBuild) 引用的任务。Creates a task to be referenced by a UsingTask Element (MSBuild).

CreateUsingTaskElement(String, String, String)

UsingTask 元素 (MSBuild) 添加到项目。Adds a UsingTask Element (MSBuild) to the project.

CreateUsingTaskElement(String, String, String, String, String)

UsingTask 元素 (MSBuild) 添加到项目。Adds a UsingTask Element (MSBuild) to the project.

CreateUsingTaskParameterElement(String, String, String, String)

创建用于 UsingTask 元素 (MSBuild) 参数组中的参数。Creates a parameter for use in a UsingTask Element (MSBuild) parameter group.

CreateUsingTaskParameterGroupElement()

UsingTask 元素 (MSBuild) 创建一个参数组。Creates a parameter group for a UsingTask Element (MSBuild).

CreateWhenElement(String)

创建具有指定 Condition 特性的 When 元素 (MSBuild)Creates a When Element (MSBuild) with a specified Condition attribute.

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
InsertAfterChild(ProjectElement, ProjectElement)

child 元素之后插入 reference 元素。Inserts the child element after the reference element.

(继承自 ProjectElementContainer)
InsertBeforeChild(ProjectElement, ProjectElement)

child 元素之前插入 reference 元素。Inserts the child element before the reference element.

(继承自 ProjectElementContainer)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
Open(String)

通过从指定文件路径加载数据,初始化全局项目集合中的项目根。Initializes a project root in the global project collection by loading data from the specified file path.

Open(String, ProjectCollection)

通过从指定文件路径加载数据,初始化指定项目集合中的项目根。Initializes a project root in the specified project collection by loading data from the specified file path.

PrependChild(ProjectElement)

child 预置为此项目容器的第一个子级。Prepends the child element as the first child of this project container.

(继承自 ProjectElementContainer)
RemoveAllChildren()

从此项目容器中移除所有子级(如果有的话)。Removes all the children, if any, from this project container.

(继承自 ProjectElementContainer)
RemoveChild(ProjectElement)

从此项目容器中移除 child 元素。Removes a child element from this project container.

(继承自 ProjectElementContainer)
Save()

将项目保存到文件系统(如果项目已修改)。Saves the project, if modified, to the file system.

Save(Encoding)

使用指定的字符编码保存项目(如果项目已修改)。Saves the project, if modified, using the specified character encoding.

Save(String)

保存项目(如果项目已修改或存储文件路径已更改)。Saves the project, if modified or if the file path to storage has changed.

Save(String, Encoding)

保存项目(如果项目已修改或存储文件路径已更改)。Saves the project, if modified or if the file path to storage has changed. 使用指定的字符编码。Uses the specified character encoding.

Save(TextWriter)

将项目保存到指定的文本编写器(无论项目是否已修改)。Saves the project to the specified text writer, whether modified or not.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)
TryOpen(String)

获取从指定文件路径加载到内存中的全局项目集合中的项目根。Gets the project root in the global project collection that was loaded into memory from the specified file path.

TryOpen(String, ProjectCollection)

获取从指定文件路径加载到内存中的指定项目集合中的项目根。Gets the project root in the specified project collection that was loaded into memory from the specified file path.

适用于