Skip to content

Commit 4b2c136

Browse files
authored
Merge pull request #1320 from MicrosoftDocs/FromPublicMaster
Confirm merge from FromPublicMaster to master to sync with https://github.com/MicrosoftDocs/visualstudio-docs (branch master)
2 parents 66c588c + 861f464 commit 4b2c136

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

docs/msbuild/customize-your-build.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ ms.workload:
2020
- "multiple"
2121
---
2222
# Customize your build
23-
In versions of MSBuild prior to version 15, if you wanted to provide a new, custom property to projects in your solution, you had to manually add a reference to that property to every project file in the solution. Or, you had to define the property in a .props file and then explicitly import the .props file in every project in the solution, among other things.
23+
In versions of MSBuild prior to version 15, if you wanted to provide a new, custom property to projects in your solution, you had to manually add a reference to that property to every project file in the solution. Or, you had to define the property in a *.props* file and then explicitly import the *.props* file in every project in the solution, among other things.
2424

25-
However, now you can add a new property to every project in one step by defining it in a single file called Directory.Build.props at the root of your repo. When MSBuild runs, Microsoft.Common.props searches your directory structure for the Directory.Build.props file (and Microsoft.Common.targets looks for Directory.Build.targets). If it finds one, it imports the property. Directory.Build.props is a user-defined file that provides customizations to projects under a directory.
25+
However, now you can add a new property to every project in one step by defining it in a single file called *Directory.Build.props* at the root of your repo. When MSBuild runs, *Microsoft.Common.props* searches your directory structure for the *Directory.Build.props* file (and *Microsoft.Common.targets* looks for *Directory.Build.targets*). If it finds one, it imports the property. *Directory.Build.props* is a user-defined file that provides customizations to projects under a directory.
2626

2727
## Directory.Build.props example
28-
For example, if you wanted to enable all of your projects to access the new Roslyn **/deterministic** feature (which is exposed in the Roslyn CoreCompile target by the property `$(Deterministic)`), you could do the following.
28+
For example, if you wanted to enable all of your projects to access the new Roslyn **/deterministic** feature (which is exposed in the Roslyn `CoreCompile` target by the property `$(Deterministic)`), you could do the following.
2929

30-
1. Create a new file in the root of your repo called Directory.Build.props.
30+
1. Create a new file in the root of your repo called *Directory.Build.props*.
3131
2. Add the following XML to the file.
3232

3333
```xml
@@ -37,10 +37,10 @@ For example, if you wanted to enable all of your projects to access the new Rosl
3737
</PropertyGroup>
3838
</Project>
3939
```
40-
3. Run MSBuild. Your project’s existing imports of Microsoft.Common.props and Microsoft.Common.targets find the file and import it.
40+
3. Run MSBuild. Your project’s existing imports of *Microsoft.Common.props* and *Microsoft.Common.targets* find the file and import it.
4141

4242
## Search scope
43-
When searching for a Directory.Build.props file, MSBuild walks the directory structure upwards from your project location ($(MSBuildProjectFullPath)), stopping after it locates a Directory.Build.props file. For example, if your $(MSBuildProjectFullPath) was c:\users\username\code\test\case1, MSBuild would start searching there and then search the directory structure upward until it located a Directory.Build.props file, as in the following directory structure.
43+
When searching for a *Directory.Build.props* file, MSBuild walks the directory structure upwards from your project location (`$(MSBuildProjectFullPath)`), stopping after it locates a *Directory.Build.props* file. For example, if your `$(MSBuildProjectFullPath)` was *c:\users\username\code\test\case1*, MSBuild would start searching there and then search the directory structure upward until it located a *Directory.Build.props* file, as in the following directory structure.
4444

4545
```
4646
c:\users\username\code\test\case1
@@ -50,13 +50,13 @@ c:\users\username
5050
c:\users
5151
c:\
5252
```
53-
The location of the solution file is irrelevant to Directory.Build.props.
53+
The location of the solution file is irrelevant to *Directory.Build.props*.
5454

5555
## Import order
5656

57-
Directory.Build.props is imported very early in Microsoft.Common.props, so properties defined later are unavailable to it. So, avoid referring to properties that are not yet defined (and will thus evaluate to empty).
57+
*Directory.Build.props* is imported very early in *Microsoft.Common.props*, so properties defined later are unavailable to it. So, avoid referring to properties that are not yet defined (and will thus evaluate to empty).
5858

59-
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.
59+
*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.
6060

6161
## Use case: multi-level merging
6262

@@ -76,20 +76,20 @@ Suppose you have this standard solution structure:
7676
\Project2Tests
7777
````
7878

79-
It might 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)`.
79+
It might 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)*.
8080

81-
For msbuild to 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 into both inner files:
81+
For MSBuild to 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 into both inner files:
8282

8383
`<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />`
8484

85-
A summary of msbuild's general approach is as follows:
85+
A summary of MSBuild's general approach is as follows:
8686

87-
- 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
87+
- 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
8888
- If you want multiple levels to be found and merged, then [`<Import...>`](../msbuild/property-functions.md#msbuild-getpathoffileabove) (shown above) the "outer" file from the "inner" file
8989
- If the "outer" file does not itself also import something above it, then scanning stops there
9090
- To control the scanning/merging process, use `$(DirectoryBuildPropsPath)` and `$(ImportDirectoryBuildProps)`
9191

92-
Or more simply: the first `Directory.Build.props` which doesn't import anything, is where msbuild stops.
92+
Or more simply: the first *Directory.Build.props* which doesn't import anything, is where MSBuild stops.
9393

9494
## See Also
9595
[MSBuild Concepts](../msbuild/msbuild-concepts.md)

0 commit comments

Comments
 (0)