Skip to content

Commit ff9ceac

Browse files
Merge pull request #13189 from ghogen/msbuild-conditions-oct-2024
MSBuild conditions syntax clarification
2 parents 1a4ab4b + c8ebfd9 commit ff9ceac

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

docs/msbuild/msbuild-conditions.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@ MSBuild supports a specific set of conditions that can be applied wherever a `Co
3434
|()|Grouping mechanism that evaluates to `true` if expressions contained inside evaluate to `true`.|
3535
|`$if$ ( %expression% ), $else$, $endif$`|Checks whether the specified `%expression%` matches the string value of the passed custom template parameter. If the `$if$` condition evaluates to `true`, then its statements are run; otherwise, the `$else$` condition is checked. If the `$else$` condition is `true`, then its statements are run; otherwise, the `$endif$` condition ends expression evaluation.<br /><br /> For examples of usage, see [Visual Studio project/item template parameter logic](https://stackoverflow.com/questions/6709057/visual-studio-project-item-template-parameter-logic).|
3636

37-
The operator `And` has higher precedence than `Or`, but for clarity, we recommend that you use parentheses when you use multiple Boolean operators to make the order of evaluation explicit. If you don't, MSBuild gives warning MSB4130.
37+
The `Condition` element is a single string, and so any strings that are used in the expression, including around property values, need to be enclosed with a single-quote. Spaces between operators are allowed and commonly used for readability, but they're not required.
38+
39+
To use the Boolean `And` and `Or` operators, specify operands inside the `Condition` element's string value, as in the following example:
40+
41+
```xml
42+
Condition="'$(Configuration)' == 'Debug' And '$(MSBuildProjectExtension)' == '.csproj'"
43+
```
44+
45+
You can chain the Boolean operators. Operator `And` has higher precedence than `Or`, but for clarity, we recommend that you use parentheses when you use multiple Boolean operators to make the order of evaluation explicit. If you don't, MSBuild gives warning MSB4130.
3846

3947
You can use string methods in conditions, as shown in the following example, in which the [TrimEnd()](/dotnet/api/system.string.trimend) function is used to compare only the relevant part of the string, to differentiate between .NET Framework and .NET Core target frameworks.
4048

0 commit comments

Comments
 (0)