User Tools

Site Tools



Properties are key/values pairs used to configure builds. A property value can be changed by re-defining the property.

  <Prop2 Condition=" '$(Prop2)' == '' ">NewValue</Prop2>

Items are inputs into the build system. 'MyItem' is the item type (or item name).

  <MyItem Include="file1.txt" />
  <MyItem Include="file2.txt" />

Tasks are units of executable code. The logic of a task is mapped to MSBuild with the <UsingTask> element.

<Target Name="MyTargetCreateDir">
  <MakeDir Directories="$(Dir)" />

Targets group tasks together in a particular order and expose sections of a proj file as entry points.

<Target Name="MyTargetCompile">
  <Csc Sources="@(File)" />

Creating properties - Properties outside of Target are assigned during the evaluation phase of a build. During the execution phase, properties can be created or modified as follows:

  • Emit a property using any Task: <Task><Output PropertyName=“…” … /></Task>
  • Embed a PropertyGroup in a Target: <Target><PropertyGroup>…</PropertyGroup></Target>
  • (depreciated) Use the CreateProperty task.
Element Reference Remarks
Property $(PropName) - used to pass values to tasks
- used to evaluate conditions
- used to store values in a proj file
$(Path) or $(PATH) - property names are not case sensitive
- values of environment variables are set at the beginning of a build and are not modified
Items @(ItemType) - a parameter for a task
- the task uses individual items
Case-sensitive Not case-sensitive
- Element Name
- Attribute Name
- Property Name
- Item Type
- Metadata Name

Example: .NET Core app:


Example: Include files and references:

  <Compile Include="**\*.cs" />
  <EmbeddedResources Include="**\*.resx />
  <PackageReference Include="Microsoft.NETCore.App" Version="1.0.1" />

Example: Default property values:

  <RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
  <RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
  <NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
  <NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
  <NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">4.7.0</NuGetToolVersion>

Example: Import another MSBuild script if it exists:

  <Import Project="C:\MyProject\Script.props" Condition="Exists('C:\MyProject\Script.props')" />

Example: Store XML in a property:

    ... XML goes here; it may contain other $props
notes/tools/msbuild.txt · Last modified: 2018/09/12 by leszek