PropertyGroup 元素 (MSBuild)PropertyGroup element (MSBuild)

包含一組使用者定義的 Property 項目。Contains a set of user-defined Property elements. MSBuildMSBuild 專案中使用的每個 Property 項目都必須是 PropertyGroup 項目的子系。Every Property element used in an MSBuildMSBuild project must be a child of a PropertyGroup element.

<Project> <PropertyGroup><Project> <PropertyGroup>

語法Syntax

<PropertyGroup Condition="'String A' == 'String B'">
    <Property1>...</Property1>
    <Property2>...</Property2>
</PropertyGroup>

屬性和元素Attributes and elements

下列章節說明屬性、子元素和父元素。The following sections describe attributes, child elements, and parent elements.

屬性Attributes

屬性Attribute 說明Description
條件Condition 選擇性屬性。Optional attribute.

要評估的條件。Condition to be evaluated. 如需詳細資訊,請參閱條件For more information, see Conditions.

子元素Child elements

元素Element 說明Description
PropertyProperty 選擇性項目。Optional element.

使用者定義的屬性名稱,其中包含屬性值。A user defined property name, which contains the property value. PropertyGroup 項目中可能有零或多個 Property 項目。There may be zero or more Property elements in a PropertyGroup element.

父元素Parent elements

元素Element 說明Description
專案Project MSBuildMSBuild 專案檔案的必要根項目。Required root element of an MSBuildMSBuild project file.

範例Example

下列程式碼範例示範如何根據條件設定屬性。The following code example shows how to set properties based on a condition. 在此範例中,如果 CompileConfig 屬性的值為 DEBUG,則會在 PropertyGroup 項目內設定 OptimizationObfuscateOutputPath 屬性。In this example, if the value of the CompileConfig property is DEBUG, the Optimization, Obfuscate, and OutputPath properties inside of the PropertyGroup element are set.

<PropertyGroup Condition="'$(CompileConfig)' == 'DEBUG'" >
    <Optimization>false</Optimization>
    <Obfuscate>false</Obfuscate>
    <OutputPath>$(OutputPath)\debug</OutputPath>
</PropertyGroup>

另請參閱See also