BuildPropertyGroup 类

定义

表示 BuildProperty 对象集合。Represents a collection of BuildProperty objects.

public ref class BuildPropertyGroup : System::Collections::IEnumerable
public class BuildPropertyGroup : System.Collections.IEnumerable
type BuildPropertyGroup = class
    interface IEnumerable
Public Class BuildPropertyGroup
Implements IEnumerable
继承
BuildPropertyGroup
实现

示例

下面的示例创建一个Project对象, 并LoadXml使用方法将内容添加到项目。The following example creates a Project object and uses the LoadXml method to add content to the project. BuildProperty、和类BuildPropertyGroupCollection用于添加、移除和更改项目中的项。 BuildPropertyGroupThe BuildProperty, BuildPropertyGroup, and BuildPropertyGroupCollection classes are used to add, remove, and change items in the project.

using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Build.BuildEngine;

namespace AddNewProperty
{
    class Program
    {
        /// <summary>
        /// This code demonstrates the use of the following methods:
        ///     Engine constructor
        ///     Project constructor
        ///     Project.LoadFromXml
        ///     Project.Xml
        ///     BuildPropertyGroupCollection.GetEnumerator
        ///     BuildPropertyGroup.GetEnumerator
        ///     BuildProperty.Name (get)
        ///     BuildProperty.Value (set)
        ///     BuildPropertyGroup.RemoveProperty
        ///     BuildPropertyGroup.AddNewProperty
        /// </summary>
        static void Main()
        {
            // Create a new Engine object.
            Engine engine = new Engine(Environment.CurrentDirectory);

            // Create a new Project object.
            Project project = new Project(engine);

            // Load the project with the following XML, which contains
            // two PropertyGroups.
            project.LoadXml(@"
                <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>

                    <PropertyGroup>
                        <Optimize>true</Optimize>
                        <WarningLevel>4</WarningLevel>
                    </PropertyGroup>

                    <PropertyGroup>
                        <OutputPath>bin\debug\</OutputPath>
                        <RemoveThisPropertyPlease>1</RemoveThisPropertyPlease>
                    </PropertyGroup>

                </Project>
                ");

            // Iterate through each PropertyGroup in the Project.  There are two.
            foreach (BuildPropertyGroup pg in project.PropertyGroups)
            {
                BuildProperty propertyToRemove = null;

                // Iterate through each Property in the PropertyGroup.
                foreach (BuildProperty property in pg)
                {
                    // If the property's name is "RemoveThisPropertyPlease", then
                    // store a reference to this property in a local variable,
                    // so we can remove it later.
                    if (property.Name == "RemoveThisPropertyPlease")
                    {
                        propertyToRemove = property;
                    }

                    // If the property's name is "OutputPath", change its value
                    // from "bin\debug\" to "bin\release\".
                    if (property.Name == "OutputPath")
                    {
                        property.Value = @"bin\release\";
                    }
                }

                // Remove the property named "RemoveThisPropertyPlease" from the
                // PropertyGroup
                if (propertyToRemove != null)
                {
                    pg.RemoveProperty(propertyToRemove);
                }

                // For each PropertyGroup that we found, add to the end of it
                // a new property called "MyNewProperty".
                pg.AddNewProperty("MyNewProperty", "MyNewValue");
            }

            // The project now looks like this:
            //
            //     <?xml version="1.0" encoding="utf-16"?>
            //     <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
            //         <Optimize>true</Optimize>
            //         <WarningLevel>4</WarningLevel>
            //         <MyNewProperty>MyNewValue</MyNewProperty>
            //         <OutputPath>bin\release</OutputPath>
            //         <MyNewProperty>MyNewValue</MyNewProperty>
            Console.WriteLine(project.Xml);
        }
    }
}
Module Module1

    ''' <summary>
    ''' This code demonstrates the use of the following methods:
    '''     Engine constructor
    '''     Project constructor
    '''     Project.LoadFromXml
    '''     Project.Xml
    '''     BuildPropertyGroupCollection.GetEnumerator
    '''     BuildPropertyGroup.GetEnumerator
    '''     BuildProperty.Name (get)
    '''     BuildProperty.Value (set)
    '''     BuildPropertyGroup.RemoveProperty
    '''     BuildPropertyGroup.AddNewProperty
    ''' </summary>
    ''' <remarks></remarks>
    Sub Main()

        ' Create a new Engine object.
        Dim engine As New Engine(Environment.CurrentDirectory)

        ' Create a new Project object.
        Dim project As New Project(engine)

        ' Load the project with the following XML, which contains
        ' two PropertyGroups.
        project.LoadXml( _
            "<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>" & _
                "<PropertyGroup>" & _
                    "<Optimize>true</Optimize>" & _
                    "<WarningLevel>4</WarningLevel>" & _
                "</PropertyGroup>" & _
                "<PropertyGroup>" & _
                    "<OutputPath>bin\debug\</OutputPath>" & _
                    "<RemoveThisPropertyPlease>1</RemoveThisPropertyPlease>" & _
                "</PropertyGroup>" & _
            "</Project>")

        ' Iterate through each PropertyGroup in the Project.  There are two.
        For Each pg As BuildPropertyGroup In project.PropertyGroups

            Dim propertyToRemove As BuildProperty
            propertyToRemove = Nothing

            ' Iterate through each Property in the PropertyGroup.
            For Each buildProperty As BuildProperty In pg

                ' If the property's name is "RemoveThisPropertyPlease", then
                ' store a reference to this property in a local variable,
                ' so we can remove it later.
                If buildProperty.Name = "RemoveThisPropertyPlease" Then
                    propertyToRemove = buildProperty
                End If

                ' If the property's name is "OutputPath", change its value
                ' from "bin\debug\" to "bin\release\".
                If buildProperty.Name = "OutputPath" Then
                    buildProperty.Value = "bin\release\"
                End If

            Next

            ' Remove the property named "RemoveThisPropertyPlease" from the
            ' PropertyGroup
            If Not propertyToRemove Is Nothing Then
                pg.RemoveProperty(propertyToRemove)
            End If

            ' For each PropertyGroup that we found, add to the end of it
            ' a new property called "MyNewProperty".
            pg.AddNewProperty("MyNewProperty", "MyNewValue")

        Next

        '  The project now looks like this:
        ' 
        '      <?xml version="1.0" encoding="utf-16"?>
        '      <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        '          <Optimize>true</Optimize>
        '          <WarningLevel>4</WarningLevel>
        '          <MyNewProperty>MyNewValue</MyNewProperty>
        '          <OutputPath>bin\release</OutputPath>
        '          <MyNewProperty>MyNewValue</MyNewProperty>
        Console.WriteLine(project.Xml)

    End Sub

End Module

注解

BuildPropertyGroup对象可以表示项目中的元素或属性的虚拟集合, 如全局属性或环境变量属性。A BuildPropertyGroup object can represent a element in the project, or a virtual collection of properties, such as global properties or environment variable properties.

构造函数

BuildPropertyGroup()

初始化 BuildPropertyGroup 类的新实例。Initializes a new instance of the BuildPropertyGroup class.

BuildPropertyGroup(Project)

初始化指定项目中的新 PropertyGroup 元素。Initializes a new PropertyGroup element in the specified project.

属性

Condition

获取或设置属性组的 Condition 特性值。Gets or sets the Condition attribute value of the property group.

Count

获取一个值,该值指示 BuildPropertyBuildPropertyGroup 对象的数目。Gets a value indicating the number of BuildProperty objects in the BuildPropertyGroup.

IsImported

获取或设置一个值,该值指示属性组是否已导入项目中。Gets or sets a value indicating whether the property group was imported into the project.

Item[String]

获取或设置此 BuildProperty 中的 BuildPropertyGroup 对象。Gets or sets a BuildProperty object in this BuildPropertyGroup.

方法

AddNewProperty(String, String)

BuildProperty 添加具有指定 NameValue 的新 BuildPropertyGroupAdds a new BuildProperty with the specified Name and Value to the BuildPropertyGroup.

AddNewProperty(String, String, Boolean)

BuildProperty 添加具有指定 NameValue 的新 BuildPropertyGroupAdds a new BuildProperty with the specified Name and Value to the BuildPropertyGroup.

Clear()

Condition 中移除 BuildProperty 属性值和所有 BuildPropertyGroup 对象。Removes the Condition property value and all BuildProperty objects from the BuildPropertyGroup.

Clone(Boolean)

创建 BuildPropertyGroup 的深层副本或浅表副本。Creates a deep or shallow copy of the BuildPropertyGroup.

Equals(Object)

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

(继承自 Object)
GetEnumerator()

获取循环访问 BuildPropertyGroup 的枚举数。Gets an enumerator that iterates through the BuildPropertyGroup.

GetHashCode()

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

(继承自 Object)
GetType()

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

(继承自 Object)
MemberwiseClone()

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

(继承自 Object)
RemoveProperty(BuildProperty)

BuildProperty 中移除指定的 BuildPropertyGroupRemoves the specified BuildProperty from the BuildPropertyGroup.

RemoveProperty(String)

BuildProperty 中移除具有指定 NameBuildPropertyGroupRemoves the BuildProperty with the specified Name from the BuildPropertyGroup.

SetImportedPropertyGroupCondition(String)

设置导入的属性组的条件。Sets the condition for imported property groups. 不保存更改。Changes are not persisted.

SetProperty(String, String)

设置具有指定 ValueBuildPropertyNameSets the Value of the BuildProperty with the specified Name.

SetProperty(String, String, Boolean)

设置具有指定 ValueBuildPropertyNameSets the Value of the BuildProperty with the specified Name.

ToString()

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

(继承自 Object)

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于