Project Element (MSBuild)

 

For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

Required root element of an MSBuild project file.

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

The following sections describe attributes, child elements, and parent elements.

Attributes

AttributeDescription
DefaultTargetsOptional 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.

If no default target is specified in either the DefaultTargets attribute or the MSBuild command line, the engine executes the first target in the project file after the Import elements have been evaluated.
InitialTargetsOptional attribute.

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.
ToolsVersionOptional attribute.

The version of the toolset MSBuild uses to determine the values for $(MSBuildBinPath) and $(MSBuildToolsPath).
TreatAsLocalPropertyOptional 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. 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. Note: You set global properties at a command prompt by using the /property (or /p) switch. 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. For more information, see MSBuild Task.
XmlnsRequired attribute.

The xmlns attribute must have the value of "http://schemas.microsoft.com/developer/msbuild/2003".

Child Elements

ElementDescription
ChooseOptional element.

Evaluates child elements to select one set of ItemGroup elements and/or PropertyGroup elements to evaluate.
ImportOptional element.

Enables a project file to import another project file. There may be zero or more Import elements in a project.
ItemGroupOptional element.

A grouping element for individual items. Items are specified by using the Item element. There may be zero or more ItemGroup elements in a project.
ProjectExtensionsOptional element.

Provides a way to persist non-MSBuild information in an MSBuild project file. There may be zero or one ProjectExtensions elements in a project.
PropertyGroupOptional element.

A grouping element for individual properties. Properties are specified by using the Property element. There may be zero or more PropertyGroup elements in a project.
TargetOptional element.

Contains a set of tasks for MSBuild to sequentially execute. Tasks are specified by using the Task element. There may be zero or more Target elements in a project.
UsingTaskOptional element.

Provides a way to register tasks in MSBuild. There may be zero or more UsingTask elements in a project.

Parent Elements

None.

How to: Specify Which Target to Build First
Command-Line Reference
Project File Schema Reference
MSBuild

Show: