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
+13-13Lines changed: 13 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -70,7 +70,7 @@ The location of the solution file is irrelevant to *Directory.Build.props*.
70
70
71
71
Properties that are set in *Directory.Build.props* can be overridden elsewhere in the project file or in imported files, so you should think of the settings in *Directory.Build.props* as specifying the defaults for your projects.
72
72
73
-
*Directory.Build.targets* is imported from *Microsoft.Common.targets* after importing *.targets* files from NuGet packages. So, it can override properties and targets defined in most of the build logic, or set properties for all your projects regardless of what the individual projects set.
73
+
*Directory.Build.targets* is imported from *Microsoft.Common.targets* after importing `.targets` files from NuGet packages. So, it can override properties and targets defined in most of the build logic, or set properties for all your projects regardless of what the individual projects set.
74
74
75
75
When you need to set a property or define a target for an individual project that overrides any prior settings, put that logic in the project file after the final import. In order to do this in an SDK-style project, you first have to replace the SDK-style attribute with the equivalent imports. See [How to use MSBuild project SDKs](how-to-use-project-sdk.md).
76
76
@@ -114,29 +114,29 @@ Or more simply: the first *Directory.Build.props* that doesn't import anything i
114
114
115
115
MSBuild is import-order dependent, and the last definition of a property (or a `UsingTask` or target) is the definition used.
116
116
117
-
When using explicit imports, you can import from a *.props* or *.targets* file at any point. Here is the widely used convention:
117
+
When using explicit imports, you can import from a `.props` or `.targets` file at any point. Here is the widely used convention:
118
118
119
-
-*.props* files are imported early in the import order.
119
+
-`.props` files are imported early in the import order.
120
120
121
-
-*.targets* files are imported late in the build order.
121
+
-`.targets` files are imported late in the build order.
122
122
123
123
This convention is enforced by `<Project Sdk="SdkName">` imports (that is, the import of *Sdk.props* comes first, before all of the contents of the file, then *Sdk.targets* comes last, after all of the contents of the file).
124
124
125
125
When deciding where to put the properties, use the following general guidelines:
126
126
127
127
- For many properties, it doesn't matter where they're defined, because they're not overwritten and will be read only at execution time.
128
128
129
-
- For behavior that might be customized in an individual project, set defaults in *.props* files.
129
+
- For behavior that might be customized in an individual project, set defaults in `.props` files.
130
130
131
-
- Avoid setting dependent properties in *.props* files by reading the value of a possibly customized property, because the customization won't happen until MSBuild reads the user's project.
131
+
- Avoid setting dependent properties in `.props` files by reading the value of a possibly customized property, because the customization won't happen until MSBuild reads the user's project.
132
132
133
-
- Set dependent properties in *.targets* files, because they'll pick up customizations from individual projects.
133
+
- Set dependent properties in `.targets` files, because they'll pick up customizations from individual projects.
134
134
135
-
- If you need to override properties, do it in a *.targets* file, after all user-project customizations have had a chance to take effect. Be cautious when using derived properties; derived properties may need to be overridden as well.
135
+
- If you need to override properties, do it in a `.targets` file, after all user-project customizations have had a chance to take effect. Be cautious when using derived properties; derived properties may need to be overridden as well.
136
136
137
-
- Include items in *.props* files (conditioned on a property). All properties are considered before any item, so user-project property customizations get picked up, and this gives the user's project the opportunity to `Remove` or `Update` any item brought in by the import.
137
+
- Include items in `.props` files (conditioned on a property). All properties are considered before any item, so user-project property customizations get picked up, and this gives the user's project the opportunity to `Remove` or `Update` any item brought in by the import.
138
138
139
-
- Define targets in *.targets* files. However, if the *.targets* file is imported by an SDK, remember that this scenario makes overriding the target more difficult because the user's project doesn't have a place to override it by default.
139
+
- Define targets in `.targets` files. However, if the `.targets` file is imported by an SDK, remember that this scenario makes overriding the target more difficult because the user's project doesn't have a place to override it by default.
140
140
141
141
- If possible, prefer customizing properties at evaluation time over changing properties inside a target. This guideline makes it easier to load a project and understand what it's doing.
142
142
@@ -265,17 +265,17 @@ If you have a dedicated build server and want to ensure that certain targets alw
265
265
266
266
## Customize C++ builds
267
267
268
-
For C++ projects, the previously mentioned custom *.targets* and *.props* files cannot be used in the same way to override default settings. *Directory.Build.props* is imported by *Microsoft.Common.props*, which is imported in `Microsoft.Cpp.Default.props` while most of the defaults are defined in *Microsoft.Cpp.props* and for a number of properties a "if not yet defined" condition cannot be used, as the property is already defined, but the default needs to be different for particular project properties defined in `PropertyGroup` with `Label="Configuration"` (see [.vcxproj and .props file structure](/cpp/build/reference/vcxproj-file-structure)).
268
+
For C++ projects, the previously mentioned custom `.targets` and `.props` files cannot be used in the same way to override default settings. *Directory.Build.props* is imported by *Microsoft.Common.props*, which is imported in `Microsoft.Cpp.Default.props` while most of the defaults are defined in *Microsoft.Cpp.props* and for a number of properties a "if not yet defined" condition cannot be used, as the property is already defined, but the default needs to be different for particular project properties defined in `PropertyGroup` with `Label="Configuration"` (see [.vcxproj and .props file structure](/cpp/build/reference/vcxproj-file-structure)).
269
269
270
-
But, you can use the following properties to specify *.props* file(s) to be automatically imported before/after *Microsoft.Cpp.\** files:
270
+
But, you can use the following properties to specify `.props` file(s) to be automatically imported before/after *Microsoft.Cpp.\** files:
271
271
272
272
- ForceImportAfterCppDefaultProps
273
273
- ForceImportBeforeCppProps
274
274
- ForceImportAfterCppProps
275
275
- ForceImportBeforeCppTargets
276
276
- ForceImportAfterCppTargets
277
277
278
-
To customize the default values of properties for all C++ builds, create another *.props* file (say, *MyProps.props*), and define the `ForceImportAfterCppProps` property in `Directory.Build.props` pointing to it:
278
+
To customize the default values of properties for all C++ builds, create another `.props` file (say, *MyProps.props*), and define the `ForceImportAfterCppProps` property in `Directory.Build.props` pointing to it:
0 commit comments