本文整理汇总了C#中Microsoft.Build.BuildEngine.BuildProperty.Name属性的典型用法代码示例。如果您正苦于以下问题:C# BuildProperty.Name属性的具体用法?C# BuildProperty.Name怎么用?C# BuildProperty.Name使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类Microsoft.Build.BuildEngine.BuildProperty
的用法示例。
在下文中一共展示了BuildProperty.Name属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
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);
}
}
}