Skip to content

Fix unquoted MSBuild condition operands (Rule B-2)#9051

Merged
Evangelink merged 3 commits into
mainfrom
copilot/msbuild-quality-fix-errors
Jun 12, 2026
Merged

Fix unquoted MSBuild condition operands (Rule B-2)#9051
Evangelink merged 3 commits into
mainfrom
copilot/msbuild-quality-fix-errors

Conversation

Copilot AI commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

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:

    <!-- Before -->
    <TestingExtensionsProfile Condition=" $(TestingExtensionsProfile) == '' ">Default</TestingExtensionsProfile>
    <!-- After -->
    <TestingExtensionsProfile Condition=" '$(TestingExtensionsProfile)' == '' ">Default</TestingExtensionsProfile>
  • src/Package/MSTest.Sdk/Sdk/Sdk.targets — unquoted MSBuild function call on LHS of second operand in a compound condition:

    <!-- Before -->
    <IsTestApplication Condition=" '$(IsTestApplication)' == '' AND $([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETStandard' ">false</IsTestApplication>
    <!-- After -->
    <IsTestApplication Condition=" '$(IsTestApplication)' == '' AND '$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)'))' == '.NETStandard' ">false</IsTestApplication>
  • test/Directory.Build.targets — same class of defect, test infrastructure only:

    <!-- Before -->
    <TestingPlatformCommandLineArguments Condition=" $([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETCoreApp' ">...
    <!-- After -->
    <TestingPlatformCommandLineArguments Condition=" '$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)'))' == '.NETCoreApp' ">...

Copilot AI requested review from Copilot and removed request for Copilot June 11, 2026 17:57
Co-authored-by: YuliiaKovalova <95473390+YuliiaKovalova@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 11, 2026 18:04
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
Copilot AI requested a review from YuliiaKovalova June 11, 2026 18:04
@Evangelink Evangelink marked this pull request as ready for review June 11, 2026 19:25
Copilot AI review requested due to automatic review settings June 11, 2026 19:25

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 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 in Common.targets.
  • Quote the result of MSBuild::GetTargetFrameworkIdentifier(...) when used as an operand in a compound condition in Sdk.targets.
  • Apply the same quoting fix for MSBuild::GetTargetFrameworkIdentifier(...) in test/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>
@Evangelink Evangelink merged commit 28677bd into main Jun 12, 2026
27 checks passed
@Evangelink Evangelink deleted the copilot/msbuild-quality-fix-errors branch June 12, 2026 09:51
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.

4 participants