An <ItemGroup> contains items (that typically represent files to be compiled etc.). The value of these items is later referred to with the @(item-name) syntax.
The following *.csproj file compiles src_1.cs and src_2.cs. Note: the individual source file names need to be separated with semicolons (;).
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Say something" >
<Message Text="Hello world." />
<Message Text="some text with low importance" Importance="low" /> <!-- not printed by default -->
<Message Text="some text with normal importance" Importance="normal" />
<Message Text="some text with high importance" Importance="high" />
</Target>
</Project>
When executed, it prints the messages as shown in the image balow.
Note, that by default, messages with low importance are not printed. Messages with high importance are rendered slightly brighter than normally important messages:
Targets
A <Target> allows to bundle multiple tasks. A project file might contain multiple targets. When running MS Build, it determines which targets it invokes.
The following project file defines three targets. By default, (only) the first target es executed:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="tgt_1">
<Message Text="Target one is being executed" />
</Target>
<Target Name="tgt_2">
<Message Text="Target two is being executed" />
</Target>
<Target Name="tgt_3">
<Message Text="Target three is being executed" />
</Target>
</Project>
The DependsOnTargets attribute of the <Target> element allows to specifiy targets that need to be executed before the target with this attribute is executed. This allows to formulate dependency-rules in a project file.
In the following example, tgt_2 is dependent on tgt_1 while tgt_4 is depdent on tgt_3 and tgt_2. Because the dependency rules are transitive, tgt_4 is also dependent on tgt_1.
In addtion, the following project file uses the DefaultTargets attribute of <Project> to control which target(s) need to be built in absence of a -t flag:
<Project
DefaultTargets="tgt_2"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
>
<Target Name="tgt_1">
<Message Text="Target one is being executed" />
</Target>
<Target Name="tgt_2" DependsOnTargets="tgt_1">
<Message Text="Target two is being executed" />
</Target>
<Target Name="tgt_3">
<Message Text="Target three is being executed" />
</Target>
<Target Name="tgt_4" DependsOnTargets="tgt_3;tgt_2">
<Message Text="Target four is being executed" />
</Target>
</Project>
The <PropertyGroup> tag contains properties. A property is simply a key/value pair. The tag-names within <PropertyGroup> correspond to the proporty names, their data to the property values.
The value of a property is referred to with the $(propertyName) syntax.
The following <PropertyGroup> defines a property named BuildDir whose value is bin:
Apparently, with such an Sdk, MS build, creates an in-memory(?) version of the .csproj where it implicitly places two <Import> tags into the .csproj file and removes the Sdk attribute from the <Project> tag.
This in-memory version then becomes something like