Project.PropertyGroups 属性
定义
获取使用项目中的 PropertyGroup 元素指定的属性组的集合。Gets a collection of the property groups specified with the PropertyGroup element in the project.
public:
property Microsoft::Build::BuildEngine::BuildPropertyGroupCollection ^ PropertyGroups { Microsoft::Build::BuildEngine::BuildPropertyGroupCollection ^ get(); };
public Microsoft.Build.BuildEngine.BuildPropertyGroupCollection PropertyGroups { get; }
member this.PropertyGroups : Microsoft.Build.BuildEngine.BuildPropertyGroupCollection
Public ReadOnly Property PropertyGroups As BuildPropertyGroupCollection
属性值
BuildPropertyGroupCollection包含在项目中指定的属性组的。A BuildPropertyGroupCollection containing the property groups specified in the project.
示例
下面的示例创建一个 Project 对象,并使用 BuildItem 、 BuildProperty BuildItemGroup 和 BuildPropertyGroup 类列出项目中的所有项和属性。The following example creates a Project object and uses the BuildItem, BuildPropertyBuildItemGroup, and BuildPropertyGroup classes to list all the items and properties in the project.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Build.BuildEngine;
namespace ListItemAndPropertiesCS
{
class Program
{
static void Main(string[] args)
{
// SET THIS TO POINT TO THE RIGHT LOCATION
Engine.GlobalEngine.BinPath = @"C:\Windows\Microsoft.NET\Framework\v2.0.xxxxx";
// Create a new empty project
Project project = new Project();
// Load a project
project.Load(@"c:\temp\validate.proj");
Console.WriteLine("Project Properties");
Console.WriteLine("----------------------------------");
// Iterate through the various property groups and subsequently
// through the various properties
foreach (BuildPropertyGroup propertyGroup in project.PropertyGroups)
{
foreach (BuildProperty prop in propertyGroup)
{
Console.WriteLine("{0}:{1}", prop.Name, prop.Value);
}
}
Console.WriteLine();
Console.WriteLine("Project Items");
Console.WriteLine("----------------------------------");
// Iterate through the various itemgroups
// and subsequently through the items
foreach (BuildItemGroup itemGroup in project.ItemGroups)
{
foreach (BuildItem item in itemGroup)
{
Console.WriteLine("{0}:{1}", item.Name, item.Include);
}
}
}
}
}
Module Module1
'You need to add references to Microsoft.Build.BuildEngine and
'Microsoft.Build.Framework
Sub Main()
'Set this to point to the location where the 2.0 clr/tools are installed
Engine.GlobalEngine.BinPath = "C:\windows\microsoft.net\framework\v2.0.xxxxx"
'Create a new empty project
Dim project As New Project()
'Load a project
project.Load("c:\temp\validate.proj")
'Output a header
Console.WriteLine("Project Properties")
Console.WriteLine("----------------------------------")
'Iterate through the various property groups and subsequently
'through the various properties
For Each propertyGroup As BuildPropertyGroup In project.PropertyGroups
For Each prop As BuildProperty In propertyGroup
Console.WriteLine("{0}:{1}", prop.Name, prop.Value)
Next
Next
Console.WriteLine()
Console.WriteLine("Project Items")
Console.WriteLine("----------------------------------")
'Iterate through the various itemgroups
'and subsequently through the items
For Each itemGroup As BuildItemGroup In project.ItemGroups
For Each item As BuildItem In itemGroup
Console.WriteLine("{0}:{1}", item.Name, item.Include)
Next
Next
End Sub
End Module
注解
BuildPropertyGroupCollection此属性返回的包含此项目中的属性组和所有导入的项目。The BuildPropertyGroupCollection returned by this property contains the property groups in this project and all imported projects.