Project 元素 (MSBuild)Project element (MSBuild)

MSBuildMSBuild 專案檔案的必要根項目。Required root element of an MSBuildMSBuild project file.

語法Syntax

<Project InitialTargets="TargetA;TargetB"
         DefaultTargets="TargetC;TargetD"
         TreatAsLocalProperty="PropertyA;PropertyB"
         ToolsVersion=<version number>
         Sdk="name[/version]"
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Sdk... />
    <Choose>... </Choose>
    <PropertyGroup>... </PropertyGroup>
    <ItemGroup>... </ItemGroup>
    <Target>... </Target>
    <UsingTask.../>
    <ProjectExtensions>... </ProjectExtensions>
    <Import... />
</Project>

屬性和元素Attributes and elements

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

屬性Attributes

屬性Attribute 說明Description
DefaultTargets 選擇性屬性。Optional attribute.

如果未指定任何目標,則為一或多個做為組建進入點的預設目標。The default target or targets to be the entry point of the build if no target has been specified. 請以分號 (;) 來分隔多個目標。Multiple targets are semi-colon (;) delimited.

如果未在 DefaultTargets 屬性或 MSBuildMSBuild 命令列中指定任何預設目標,則引擎會在已評估 Import 項目之後執行專案中的第一個目標。If no default target is specified in either the DefaultTargets attribute or the MSBuildMSBuild command line, the engine executes the first target in the project file after the Import elements have been evaluated.
InitialTargets 選擇性屬性。Optional attribute.

要在 DefaultTargets 屬性中或命令列上指定目標之前執行的一或多個初始目標。The initial target or targets to be run before the targets specified in the DefaultTargets attribute or on the command line. 請以分號 (;) 來分隔多個目標。Multiple targets are semi-colon (;) delimited. 如果多個匯入的檔案定義 InitialTargets,則提到的所有目標都會按照進行匯入的順序執行。If multiple imported files define InitialTargets, all targets mentioned will be run, in the order the imports are encountered.
Sdk 選擇性屬性。Optional attribute.

要用來建立隱含 Import 陳述式 (會將它新增至 .proj 檔案) 的 SDK 名稱和選擇性版本。The SDK name and optional version to use to create implicit Import statements that are added to the .proj file. 如果未指定版本,MSBuild 會嘗試解析預設版本。If no version is specified, MSBuild will attempt to resolve a default version. 例如,<Project Sdk="Microsoft.NET.Sdk" /><Project Sdk="My.Custom.Sdk/1.0.0" />For example, <Project Sdk="Microsoft.NET.Sdk" /> or <Project Sdk="My.Custom.Sdk/1.0.0" />.
ToolsVersion 選擇性屬性。Optional attribute.

MSBuild 用來判斷 $(MSBuildBinPath) 和 $(MSBuildToolsPath) 之值的工具組版本。The version of the Toolset MSBuild uses to determine the values for $(MSBuildBinPath) and $(MSBuildToolsPath).
TreatAsLocalProperty 選擇性屬性。Optional attribute.

將不會被視為全域的屬性名稱。Property names that won't be considered to be global. 這個屬性可防止特定的命令列屬性覆寫專案檔或目標檔案及所有後續匯入中設定的屬性值。This attribute prevents specific command-line properties from overriding property values that are set in a project or targets file and all subsequent imports. 請以分號 (;) 來分隔多個屬性。Multiple properties are semi-colon (;) delimited.

一般來說,全域屬性值會覆寫專案檔或目標檔案中所設定的屬性值。Normally, global properties override property values that are set in the project or targets file. 如果此屬性列於 TreatAsLocalProperty 值中,則全域屬性值不會覆寫該檔案及任何後續匯入中所設定的屬性值。If the property is listed in the TreatAsLocalProperty value, the global property value doesn't override property values that are set in that file and any subsequent imports. 如需詳細資訊,請參閱如何:使用不同選項來建置相同的來源檔案For more information, see How to: Build the same source files with different options. 注意: 您可以使用 -property (或 -p) 參數,在命令提示字元中設定全域屬性。Note: You set global properties at a command prompt by using the -property (or -p) switch. 您也可以使用 MSBuild 工作的 Properties 屬性,針對多專案組建中的子專案設定或修改全域屬性。You can also set or modify global properties for child projects in a multi-project build by using the Properties attribute of the MSBuild task. 如需詳細資訊,請參閱 MSBuild 工作For more information, see MSBuild task.
xmlns 選擇性屬性。Optional attribute.

指定時,xmlns 屬性的值必須為 http://schemas.microsoft.com/developer/msbuild/2003When specified, the xmlns attribute must have the value of http://schemas.microsoft.com/developer/msbuild/2003.

子元素Child elements

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

評估子項目,以選取一組要評估的 ItemGroup 項目和/或 PropertyGroup 項目。Evaluates child elements to select one set of ItemGroup elements and/or PropertyGroup elements to evaluate.
ImportImport 選擇性項目。Optional element.

可讓專案檔案匯入另一個專案檔。Enables a project file to import another project file. 專案中可能有零或多個 Import 項目。There may be zero or more Import elements in a project.
ImportGroupImportGroup 選擇性項目。Optional element.

包含群組在選擇性條件下方的 Import 元素集合。Contains a collection of Import elements that are grouped under an optional condition.
ItemGroupItemGroup 選擇性項目。Optional element.

個別項目 (Item) 的群組項目 (Element)。A grouping element for individual items. 使用 Item 項目 (Element) 來指定項目 (Item)。Items are specified by using the Item element. 專案中可能有零或多個 ItemGroup 項目。There may be zero or more ItemGroup elements in a project.
ItemDefinitionGroupItemDefinitionGroup 選擇性項目。Optional element.

可讓您定義一組項目定義,這些項目定義預設為套用至專案中所有項目的中繼資料值。Lets you define a set of Item Definitions, which are metadata values that are applied to all items in the project, by default. ItemDefinitionGroup 可取代使用 CreateItem 工作和 CreateProperty 工作的需求。ItemDefinitionGroup supersedes the need to use the CreateItem task and the CreateProperty task.
ProjectExtensionsProjectExtensions 選擇性項目。Optional element.

提供一種方式,在 MSBuildMSBuild 專案檔保存非 MSBuildMSBuild 的資訊。Provides a way to persist non-MSBuildMSBuild information in an MSBuildMSBuild project file. 專案中可能有零或一個 ProjectExtensions 項目。There may be zero or one ProjectExtensions elements in a project.
PropertyGroupPropertyGroup 選擇性項目。Optional element.

個別屬性的群組項目。A grouping element for individual properties. 使用 Property 項目來指定屬性。Properties are specified by using the Property element. 專案中可能有零或多個 PropertyGroup 項目。There may be zero or more PropertyGroup elements in a project.
SdkSdk 選擇性項目。Optional element.

參考 MSBuildMSBuild 專案 SDK。References an MSBuildMSBuild project SDK. 此元素可用來當做 Sdk 屬性的替代方案。This element can be used as an alternative to the Sdk attribute.
TargetTarget 選擇性項目。Optional element.

包含一組可循序執行的 MSBuildMSBuild 工作。Contains a set of tasks for MSBuildMSBuild to sequentially execute. 使用 Item 項目來指定工作。Tasks are specified by using the Task element. 專案中可能有零或多個 Target 項目。There may be zero or more Target elements in a project.
UsingTaskUsingTask 選擇性項目。Optional element.

提供一種方式,在 MSBuildMSBuild 中登錄工作。Provides a way to register tasks in MSBuildMSBuild. 專案中可能有零或多個 UsingTask 項目。There may be zero or more UsingTask elements in a project.

父元素Parent elements

無。None.

另請參閱See also