Skip to content

Commit 74060a8

Browse files
authored
Merge pull request #10752 from zsd4yr/patch-1
Update higher level Directory.Build.props import to only run if the file actually exists
2 parents 2398351 + 083375f commit 74060a8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

docs/msbuild/customize-by-directory.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,15 @@ It might be desirable to have common properties for all projects *(1)*, common p
118118
To make MSBuild correctly merge the "inner" files (*2-src* and *2-test*) with the "outer" file (*1*), you 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 code into both inner files:
119119

120120
```xml
121-
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
121+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" Condition="'' != $([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
122122
```
123123

124124
A summary of MSBuild's general approach is as follows:
125125

126126
- 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.
127127
- If you want multiple levels to be found and merged, then [`<Import...>`](../msbuild/property-functions.md#msbuild-getpathoffileabove) (shown previously) the "outer" file from the "inner" file.
128128
- If the "outer" file doesn't itself also import something above it, then scanning stops there.
129+
- Only do this if the uupper level file actual exists
129130

130131
Or more simply: the first *Directory.Build.props* that doesn't import anything is where MSBuild stops.
131132

0 commit comments

Comments
 (0)