What are MSBuild properties and items, and how do they control the build process?
Short answer
MSBuild properties (in PropertyGroup, e.g., , , ) are single named values controlling build behavior, while items (in ItemGroup, e.g., , , ) represent lists of inputs like source files, package dependencies, or project references.
Advertisement
AModel answer
MSBuild properties (in PropertyGroup, e.g., <TargetFramework>, <Nullable>, <LangVersion>) are single named values controlling build behavior, while items (in ItemGroup, e.g., <PackageReference>, <Compile>, <ProjectReference>) represent lists of inputs like source files, package dependencies, or project references. MSBuild evaluates these to construct and execute the actual build graph (compilation, resource embedding, packaging).
<PropertyGroup>
<OutputType>Exe</OutputType>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Legacy/**/*.cs" />
<ProjectReference Include="..\MyLib\MyLib.csproj" />
</ItemGroup>Real-world example
A project excludes an obsolete Legacy folder from compilation using a Compile Remove item, keeping the dead code in source control for reference without it being built.
Likely follow-ups
- How do custom MSBuild targets extend the build process?
- What's the difference between PropertyGroup and ItemGroup evaluation order?
Related topics