Skip to content

Quote left side of MSBuild condition expressions - #16325

Merged
Azat Mukhametshin (azat-msft) merged 1 commit into
microsoft:mainfrom
azat-msft:azat-msft-fix-msbuild-condition-quoting
Jul 30, 2026
Merged

Azat Mukhametshin (azat-msft) merged 1 commit into
microsoft:mainfrom
azat-msft:azat-msft-fix-msbuild-condition-quoting

Conversation

@azat-msft

Copy link
Copy Markdown
Member

Fixes the two rule B-2 findings reported in #16308.

  • Directory.Build.props: <NetPrevious Condition=" $(NetPrevious) == '' "> → '$(NetPrevious)'
  • Directory.Build.targets: <When Condition="$(TestProject) == 'true' AND ..."> → '$(TestProject)'

Unquoted properties on the left of == expand to nothing when unset, which can yield a malformed condition expression. Quoting is the standard MSBuild pattern and is semantically equivalent when the property is set.

Verified with a full build.cmd -c Release — all projects including test projects build (exercising the TestProject condition). The only failure is a pre-existing VSSDK1025 packaging error for an internal-only Cpp extension file, unrelated to this change.

Fixes #16308

Fixes rule B-2 findings from the MSBuild quality report: the left side of
== was not single-quoted in Directory.Build.props (NetPrevious) and
Directory.Build.targets (TestProject). Unquoted properties evaluate to an
empty token when unset, which can produce a malformed condition.

Fixes microsoft#16308

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: bad0e1f8-5f21-4c49-b3cf-d086f856c491
Copilot AI review requested due to automatic review settings July 30, 2026 12:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request updates MSBuild condition expressions to single-quote the left-hand property expansion in == comparisons, preventing malformed condition expressions when a property is unset (MSBuild quality rule B-2) while keeping semantics equivalent when the property is set.

Changes:

  • Quote $(TestProject) on the left side of == in Directory.Build.targets test-project gating condition.
  • Quote $(NetPrevious) on the left side of == in Directory.Build.props framework selection fallback condition.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Directory.Build.targets Quotes $(TestProject) in the <When> condition to avoid empty expansion producing malformed expressions when unset.
Directory.Build.props Quotes $(NetPrevious) in the condition for defaulting NetPrevious to NetMinimum when the property is unset/empty.

@azat-msft
Azat Mukhametshin (azat-msft) merged commit f7d5f02 into microsoft:main Jul 30, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[msbuild-quality] MSBuild File Quality Report — 2026-07-26

3 participants