You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/msbuild/customize-your-build.md
+33Lines changed: 33 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -70,6 +70,39 @@ Directory.Build.props is imported very early in Microsoft.Common.props, so prope
70
70
71
71
Directory.Build.targets is imported from Microsoft.Common.targets after importing .targets files from NuGet packages. So, it can be used to override properties and targets defined in most of the build logic, but at times it may be necessary to do customizations within the project file after the final import.
72
72
73
+
## Use case: multi-level merging
74
+
75
+
Supposing you have this standard solution structure:
76
+
77
+
````
78
+
\
79
+
MySolution.sln
80
+
Directory.Build.props (1)
81
+
\src
82
+
Directory.Build.props (2-src)
83
+
\Project1
84
+
\Project2
85
+
\test
86
+
Directory.Build.props (2-test)
87
+
\Project1Tests
88
+
\Project2Tests
89
+
````
90
+
91
+
It may be desirable to have common properties for all projects `(1)`, common properties for `src` projects `(2-src)`, and common properties for `test` projects `(2-test)`.
92
+
93
+
For msbuild to correctly merge the "inner" files (`2-src` and `2-test`) with the "outer" file (`1`), one must take into account that once msbuild finds a `Directory.Build.props` file, it stops further scanning. To continue scanning, and merge into the outer file, place this into both inner files:
A summary of msbuild's general approach is as follows:
98
+
99
+
- for any given project, msbuild finds the first `Directory.Build.props` upward in the solution structure, merges it with defaults, and stops scanning for more
100
+
- if you want multiple levels to be found and merged, then `<Import...>` (shown above) the "outer" file from the "inner" file
101
+
- if the "outer" file does not itself also import something above it, then scanning stops there
102
+
- to control the scanning/merging process, use `$(DirectoryBuildPropsPath)` and `$(ImportDirectoryBuildProps)`
103
+
104
+
Or more simply: the first `Directory.Build.props` which doesn't import anything, is where msbuild stops.
0 commit comments