Introduction To MSBuild

Click here to change the theme.

A Project element is the root element of a MSBuild project file. The most simplest sample would be:

<Project xmlns="">


MSBuild properties are simply a collection of key-value pairs consisting of names and values. Static properties are always in a PropertyGroup element. Dynamic properties are explained later. There can be multiple PropertyGroup elements but all properties are placed together in one collection. Except a PropertyGroup element can have a Condition attribute. In a PropertyGroup element, the XML tag name of the elements in it is the name of the property and the value of the property is value in the element.

A simple sample of a PropertyGroup element is:


The preceding PropertyGroup has properties with the names SchemaVersion, OutputType, AppDesignerFolder, TargetFrameworkVersion and UseIISExpress.

Tasks and Targets

Tasks and Targets specify what to do. Tasks are contained in Targets. Targets consist of one (or zero) or more Tasks. MSBuild installs many tasks, including Csc, Vsc, AspNetCompiler and Message.  The Csc task executes the C# compiler. The Vsc task executes the VB .Net compiler. The AspNetCompiler task precompiles ASP.NET applications. The Message task shows messages in the output window during a build. There are very many more tasks.


Items are an ordered list of values. Items are specified in ItemGroup elements. The item names are specified as subelements of ItemGroup elements. An "Include" attribute specifies the list of values. An entire list can be included in a single Include attribute or the list can be spread across ItemGroup elements or subelements of the ItemGroup element. Each value in the list of values is normally a file.

Items are either static or dynamic. Static items exist in the project and dynamic items exist in targets.






Creating a project file from scratch

I assume you are familiar with the Solution Explorer.




<Project ToolsVersion="4.0"



Add the following attribute to the Project element:


That will tell MSBuild to use the target named "BuildTarget" when we do a build. Next add the following subelements to the Project element:

<Target Name="BuildTarget">


<Target Name="Rebuild">
<Target Name="Clean">


Using MSBuild from the command line


I will in the future write additional articles about project files and MSBuild.

Hosted by