Share settings across multiple projects using a Directory.Build.props file

To set properties for every project in a directory in a centralized location create a Directory.Build.props file in your solution folder structure.

These files can be particularly useful when when we have large solutions with lots of projects.

The example below shows the TreatWarningsAsErrors, AccelerateBuildsInVisualStudio and the TargetFramework properties being set. A particular version of a NuGet package is also set.

Note, to manage packages for all projects in a solution Central Package Management (CPM) via a Directory.Packages.props is also an option ->
Central Package Management | Microsoft Learn

Since the settings in Directory.Build.props files are essentially defaults they make the build process a little more implicit so be sure to communicate and document any usages of these files.

What do you think?

Have you used Directory.Build.props files in your solutions before?

Leave a Reply

Your email address will not be published. Required fields are marked *