What is Directory.Build.props, and how does it help manage shared MSBuild settings across multiple projects in a repository?
Short answer
Directory.Build.props is an MSBuild file automatically imported by every project in and below the directory it resides in, letting you centralize common properties (like LangVersion, Nullable, common package versions, or company copyright metadata) without repeating them in…
Advertisement
AModel answer
Directory.Build.props is an MSBuild file automatically imported by every project in and below the directory it resides in, letting you centralize common properties (like LangVersion, Nullable, common package versions, or company copyright metadata) without repeating them in every individual .csproj file, reducing duplication and drift across a multi-project solution.
<!-- Directory.Build.props at repo root -->
<Project>
<PropertyGroup>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
</Project>Real-world example
A monorepo with 40 microservice projects uses a single Directory.Build.props to enforce nullable reference types and warnings-as-errors consistently across every project without editing each csproj individually.
Likely follow-ups
- How does Directory.Build.targets differ in import order from Directory.Build.props?
- How do you override a shared property in one specific project?
Related topics