BuildItem BuildItem BuildItem BuildItem Class

Definition

Stellt ein einzelnes Element in einem MSBuild-Projekt dar.Represents a single item in an MSBuild project.

public ref class BuildItem
public class BuildItem
type BuildItem = class
Public Class BuildItem
Vererbung
BuildItemBuildItemBuildItemBuildItem

Beispiele

Das folgende Beispiel erstellt eine Project -Objekt und verwendet die LoadXml Methode, um Inhalt zum Projekt hinzuzufügen.The following example creates a Project object and uses the LoadXml method to add content to the project. Die BuildItem, BuildItemGroup, und BuildItemGroupCollection Klassen dienen zum Hinzufügen, entfernen und Ändern von Elementen im Projekt.The BuildItem, BuildItemGroup, and BuildItemGroupCollection 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 AddNewItem
{
    class Program
    {
        /// <summary>
        /// This code demonstrates the use of the following methods:
        ///     Engine constructor
        ///     Project constructor
        ///     Project.LoadFromXml
        ///     Project.Xml
        ///     BuildItemGroupCollection.GetEnumerator
        ///     BuildItemGroup.GetEnumerator
        ///     BuildItem.Name (get)
        ///     BuildItem.Include (set)
        ///     BuildItem.GetMetadata
        ///     BuildItem.SetMetadata
        ///     BuildItemGroup.RemoveItem
        ///     BuildItemGroup.AddNewItem
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // 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 ItemGroups.
            project.LoadXml(@"
                <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>

                    <ItemGroup>
                        <Compile Include='Program.cs'/>
                        <Compile Include='Class1.cs'/>
                        <RemoveThisItemPlease Include='readme.txt'/>
                    </ItemGroup>

                    <ItemGroup>
                        <EmbeddedResource Include='Strings.resx'>
                            <LogicalName>Strings.resources</LogicalName>
                            <Culture>fr-fr</Culture>
                        </EmbeddedResource>
                    </ItemGroup>

                </Project>
                ");

            // Iterate through each ItemGroup in the Project.  There are two.
            foreach (BuildItemGroup ig in project.ItemGroups)
            {
                BuildItem itemToRemove = null;

                // Iterate through each Item in the ItemGroup.
                foreach (BuildItem item in ig)
                {
                    // If the item's name is "RemoveThisItemPlease", then
                    // store a reference to this item in a local variable,
                    // so we can remove it later.
                    if (item.Name == "RemoveThisItemPlease")
                    {
                        itemToRemove = item;
                    }

                    // If the item's name is "EmbeddedResource" and it has a metadata Culture
                    // set to "fr-fr", then ...
                    if ((item.Name == "EmbeddedResource") && (item.GetMetadata("Culture") == "fr-fr"))
                    {
                        // Change the item's Include path to "FrenchStrings.fr.resx", 
                        // and add a new metadata Visiable="false".
                        item.Include = @"FrenchStrings.fr.resx";
                        item.SetMetadata("Visible", "false");
                    }
                }

                // Remove the item named "RemoveThisItemPlease" from the
                // ItemGroup
                if (itemToRemove != null)
                {
                    ig.RemoveItem(itemToRemove);
                }

                // For each ItemGroup that we found, add to the end of it
                // a new item Content with Include="SplashScreen.bmp".
                ig.AddNewItem("Content", "SplashScreen.bmp");
            }

            // The project now looks like this:
            //
            //     <?xml version="1.0" encoding="utf-16"?>
            //     <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
            //         <Compile Include="Program.cs" />
            //         <Compile Include="Class1.cs" />
            //         <Content Include="SplashScreen.bmp" />
            //         <EmbeddedResource Include="FrenchStrings.fr.resx">
            //           <LogicalName>Strings.resources</LogicalName>
            //           <Culture>fr-fr</Culture>
            //           <Visible>false</Visible>
            //         <Content Include="SplashScreen.bmp" />
            //
            Console.WriteLine(project.Xml);
        }
    }
}
Module Module1

    ''' <summary>
    ''' This code demonstrates the use of the following methods:
    '''     Engine constructor
    '''     Project constructor
    '''     Project.LoadFromXml
    '''     Project.Xml
    '''     BuildItemGroupCollection.GetEnumerator
    '''     BuildItemGroup.GetEnumerator
    '''     BuildItem.Name (get)
    '''     BuildItem.Include (set)
    '''     BuildItem.GetMetadata
    '''     BuildItem.SetMetadata
    '''     BuildItemGroup.RemoveItem
    '''     BuildItemGroup.AddNewItem
    ''' </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 ItemGroups.
        project.LoadXml( _
            "<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>" & _
                "<ItemGroup>" & _
                    "<Compile Include='Program.cs'/>" & _
                    "<Compile Include='Class1.cs'/>" & _
                    "<RemoveThisItemPlease Include='readme.txt'/>" & _
                "</ItemGroup>" & _
                "<ItemGroup>" & _
                    "<EmbeddedResource Include='Strings.resx'>" & _
                        "<LogicalName>Strings.resources</LogicalName>" & _
                        "<Culture>fr-fr</Culture>" & _
                    "</EmbeddedResource>" & _
                "</ItemGroup>" & _
            "</Project>" _
            )

        ' Iterate through each ItemGroup in the Project.  There are two.
        For Each ig As BuildItemGroup In project.ItemGroups

            Dim itemToRemove As BuildItem
            itemToRemove = Nothing

            ' Iterate through each Item in the ItemGroup.
            For Each item As BuildItem In ig

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

                ' If the item's name is "EmbeddedResource" and it has a metadata Culture
                ' set to "fr-fr", then ...
                If (item.Name = "EmbeddedResource") And (item.GetMetadata("Culture") = "fr-fr") Then
                    ' Change the item's Include path to "FrenchStrings.fr.resx", 
                    ' and add a new metadata Visiable="false".
                    item.Include = "FrenchStrings.fr.resx"
                    item.SetMetadata("Visible", "false")
                End If
            Next

            ' Remove the item named "RemoveThisItemPlease" from the
            ' ItemGroup
            If Not itemToRemove Is Nothing Then
                ig.RemoveItem(itemToRemove)
            End If

            ' For each ItemGroup that we found, add to the end of it
            ' a new item Content with Include="SplashScreen.bmp".
            ig.AddNewItem("Content", "SplashScreen.bmp")
        Next

        ' The project now looks like this:
        '
        '     <?xml version="1.0" encoding="utf-16"?>
        '     <Project xmlns="http:'schemas.microsoft.com/developer/msbuild/2003">
        '         <Compile Include="Program.cs" />
        '         <Compile Include="Class1.cs" />
        '         <Content Include="SplashScreen.bmp" />
        '         <EmbeddedResource Include="FrenchStrings.fr.resx">
        '           <LogicalName>Strings.resources</LogicalName>
        '           <Culture>fr-fr</Culture>
        '           <Visible>false</Visible>
        '         <Content Include="SplashScreen.bmp" />
        '
        Console.WriteLine(project.Xml)

    End Sub

End Module

Hinweise

Ein Element in einem Projekt kann mehrere Elemente durch die Verwendung von Platzhaltern darstellen.An element in a project can represent multiple items through the use of wildcards. Aus diesem Grund jede BuildItem Objekt ist nicht notwendigerweise ein Item -Element im Projekt.Therefore, each BuildItem object does not necessarily represent an Item element in the project.

Konstruktoren

BuildItem(String, ITaskItem) BuildItem(String, ITaskItem) BuildItem(String, ITaskItem) BuildItem(String, ITaskItem)

Initialisiert eine neue Instanz der BuildItem-Klasse auf der Grundlage eines ITaskItem-Objekts.Initializes a new instance of the BuildItem class based on an ITaskItem object.

BuildItem(String, String) BuildItem(String, String) BuildItem(String, String) BuildItem(String, String)

Initialisiert eine neue Instanz der BuildItem-Klasse mit dem angegebenen Name-Eigenschaftswert und Include-Eigenschaftswert.Initializes a new instance of the BuildItem class with the specified Name and Include property values.

Eigenschaften

Condition Condition Condition Condition

Ruft den Attributwert Condition des Elements ab oder legt ihn festGets or sets the Condition attribute value of the item.

CustomMetadataCount CustomMetadataCount CustomMetadataCount CustomMetadataCount

Ruft die Anzahl von benutzerdefinierten Attributen ab, die für dieses Element festgelegt sind.Gets the number of custom attributes that are set on this item.

CustomMetadataNames CustomMetadataNames CustomMetadataNames CustomMetadataNames

Ruft alle benutzerdefinierten Attributnamen ab.Gets all user-defined or custom attribute names.

Exclude Exclude Exclude Exclude

Ruft den Exclude-Attributwert des Elements ab oder legt diesen fest.Gets or sets the Exclude attribute value of the item.

FinalItemSpec FinalItemSpec FinalItemSpec FinalItemSpec

Ruft die endgültige Spezifikation des Elements ab, nachdem alle Platzhalter und Eigenschaften ausgewertet wurden.Gets the final specification of the item after all wildcards and properties have been evaluated.

Include Include Include Include

Ruft das Include-Attribut ab, das das BuildItem erstellt hat oder legt dieses fest.Gets or sets the Include attribute that created the BuildItem.

IsImported IsImported IsImported IsImported

Ruft einen Wert ab, der angibt, ob das Element in das Projekt importiert wurde.Gets a value indicating whether the item was imported into the project.

MetadataCount MetadataCount MetadataCount MetadataCount

Ruft die Anzahl der für das Element festgelegten Metadaten ab.Gets the number of metadata set on the item

MetadataNames MetadataNames MetadataNames MetadataNames

Ruft die Namen der Metadaten für das Element ab, einschließlich vordefinierter oder reservierter Elementspezifikationsmodifizierer.Gets the names of metadata on the item, including pre-defined or reserved item-spec modifiers.

Name Name Name Name

Ruft den Namen der Elementauflistung ab, zu der das Element gehört, oder legt diesen fest.Gets or sets the name of the item collection to which the item belongs.

Methoden

Clone() Clone() Clone() Clone()

Erstellt eine flache Kopie von BuildItem.Creates a shallow copy of the BuildItem.

CopyCustomMetadataTo(BuildItem) CopyCustomMetadataTo(BuildItem) CopyCustomMetadataTo(BuildItem) CopyCustomMetadataTo(BuildItem)

Kopiert alle Elementmetadaten für dieses BuildItem in das angegebene BuildItem.Copies all item metadata on this BuildItem to the specified BuildItem.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Bestimmt, ob das angegebene Objekt mit dem aktuellen Objekt identisch ist.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEvaluatedMetadata(String) GetEvaluatedMetadata(String) GetEvaluatedMetadata(String) GetEvaluatedMetadata(String)

Gibt den Wert der angegebenen Elementmetadaten zurück, nachdem alle Element- und Eigenschaftenverweise ausgewertet wurden.Returns the value of the specified item metadata after all item and property references have been evaluated.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Fungiert als Standardhashfunktion.Serves as the default hash function.

(Inherited from Object)
GetMetadata(String) GetMetadata(String) GetMetadata(String) GetMetadata(String)

Gibt den Wert der angegebenen Elementmetadaten zurück.Returns the value of the specified item metadata.

GetType() GetType() GetType() GetType()

Ruft den Type der aktuellen Instanz ab.Gets the Type of the current instance.

(Inherited from Object)
HasMetadata(String) HasMetadata(String) HasMetadata(String) HasMetadata(String)

Gibt an, ob das Element die angegebenen Elementmetadaten aufweist.Indicates whether the item has the specified item metadata.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.Creates a shallow copy of the current Object.

(Inherited from Object)
RemoveMetadata(String) RemoveMetadata(String) RemoveMetadata(String) RemoveMetadata(String)

Entfernt die angegebenen Elementmetadaten.Removes the specified item metadata.

SetMetadata(String, String) SetMetadata(String, String) SetMetadata(String, String) SetMetadata(String, String)

Weist den angegebenen Elementmetadaten den angegebenen Wert zu.Assigns the specified value to the specified item metadata.

SetMetadata(String, String, Boolean) SetMetadata(String, String, Boolean) SetMetadata(String, String, Boolean) SetMetadata(String, String, Boolean)

Weist den angegebenen Elementmetadaten den angegebenen Wert zu, und behandelt die Metadaten optional als literalen Wert.Assigns the specified value to the specified item metadata, and optionally treats the metadata as a literal value.

ToString() ToString() ToString() ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.Returns a string that represents the current object.

(Inherited from Object)

Gilt für: