Fix unquoted MSBuild condition operands (Rule B-2)#9051
Merged
Conversation
Co-authored-by: YuliiaKovalova <95473390+YuliiaKovalova@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix error in Common.targets file for MSBuild quality report
Fix unquoted MSBuild condition operands (Rule B-2)
Jun 11, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes three MSBuild Condition expressions to properly single-quote the left-hand operand of ==, aligning with MSBuild condition parsing best practices (Rule B-2) and avoiding edge-case misparsing when the expanded value is empty or contains special characters. Two of the fixes are in MSTest.Sdk targets that are evaluated in consumer builds; one is in the repo’s test infrastructure targets.
Changes:
- Quote the
$(TestingExtensionsProfile)property reference on the LHS of an equality comparison inCommon.targets. - Quote the result of
MSBuild::GetTargetFrameworkIdentifier(...)when used as an operand in a compound condition inSdk.targets. - Apply the same quoting fix for
MSBuild::GetTargetFrameworkIdentifier(...)intest/Directory.Build.targets.
Show a summary per file
| File | Description |
|---|---|
test/Directory.Build.targets |
Quotes the GetTargetFrameworkIdentifier operand in a TFM-gated test command-line condition to ensure reliable condition evaluation. |
src/Package/MSTest.Sdk/Sdk/Sdk.targets |
Quotes the MSBuild function result operand in the .NETStandard gating logic for IsTestApplication. |
src/Package/MSTest.Sdk/Sdk/Runner/Common.targets |
Quotes $(TestingExtensionsProfile) in the defaulting condition to prevent malformed/ambiguous comparisons. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 0
Wrapping an MSBuild property-function call whose argument is already single-quoted (e.g. '$(TargetFramework)') in outer single quotes creates nested-quote conflicts that MSBuild cannot parse, causing MSB4092. Rule B-2 only applies to bare property references like '$(Foo)', not to function-call results. Keep only the valid Common.targets property fix. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
YuliiaKovalova
approved these changes
Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three MSBuild condition expressions were missing single quotes on the left-hand side of
==, violating MSBuild best practice (Rule B-2). Two of the affected files ship inside the MSTest.Sdk NuGet package and are evaluated for every consumer project.Changes
src/Package/MSTest.Sdk/Sdk/Runner/Common.targets— bare property reference on LHS:src/Package/MSTest.Sdk/Sdk/Sdk.targets— unquoted MSBuild function call on LHS of second operand in a compound condition:test/Directory.Build.targets— same class of defect, test infrastructure only: