Skip to content

Fix malformed MSBuild property function call in Microsoft.CSharp.Tests.csproj#126864

Merged
jkotas merged 2 commits intomainfrom
copilot/fix-malformed-msbuild-property-call
Apr 14, 2026
Merged

Fix malformed MSBuild property function call in Microsoft.CSharp.Tests.csproj#126864
jkotas merged 2 commits intomainfrom
copilot/fix-malformed-msbuild-property-call

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

Microsoft.CSharp.Tests.csproj had a missing closing ) in its <Features> property, causing MSBuild to treat the entire expression as a literal property name (evaluating to empty string) instead of invoking the Replace function. This silently cleared all compiler features — including nullablePublicOnly from Directory.Build.props — rather than surgically removing only strict.

Description

  • Before: $(Features.Replace('strict', '') — MSBuild fails to parse as a property function; evaluates to "", stripping all features
  • After: $(Features.Replace('strict', '')) — correctly evaluates to ";nullablePublicOnly", preserving other features while only removing strict

The strict feature is intentionally excluded from this test project because the tests exercise enum arithmetic operations that Roslyn's strict mode would reject.

Original prompt

In src/libraries/Microsoft.CSharp/tests/Microsoft.CSharp.Tests.csproj, line 9, there is a malformed MSBuild property function call that is missing a closing parenthesis:

<Features>$(Features.Replace('strict', '')</Features>

Because the closing ) is missing, MSBuild fails to parse this as a property function and instead treats the entire expression as a literal property name lookup. Since no such property exists, it evaluates to an empty string. This means <Features> is set to empty — which does remove strict (the intended effect), but also unintentionally removes nullablePublicOnly and any other features inherited from the repo-wide Directory.Build.props (which sets <Features>strict;nullablePublicOnly</Features>).

The fix is to add the missing closing parenthesis so the property function works correctly:

<Features>$(Features.Replace('strict', ''))</Features>

This will properly evaluate the Replace call, surgically removing only strict while preserving all other features like nullablePublicOnly.

This is the only file in the repo with this issue (confirmed via code search).

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: I'm looking at comment #126863 (comment). do we set Features=strict anywhere now? it seems like it was the intention of the commit that added the problematic line, but I don't see that commit setting it

Assistant:

Let me investigate the comment and the relevant code to understand the context.

Assistant: The comment is about this line in src/libraries/Microsoft.CSharp/tests/Microsoft.CSharp.Tests.csproj:

<Features>$(Features.Replace('strict', '')</Features>

This line tries to remove strict from the $(Features) property, but it's also missing a closing ). Let me investigate where Features=strict might be set, and look at the commit that introduced this line.

Assistant: The comment is about the line <Features>$(Features.Replace('strict', '')</Features> on line 9. I need to find the commit that originally added this line and check if Features=strict was set somewhere.

Let me look at the commit that introduced this line. Let me use git log via the blame/search approach.

Assistant: Now I can see the full picture. Let me verify the Directory.Build.props line more closely:

Assistant: Now I can see the full picture. Let me look at the specific commit that introduced the Features.Replace('strict', '') line in the Microsoft.CSharp test project to understand its history.

Assistant: Let me look at the git blame/history to find the original commit that added the Features line.

Assistant: Let me look at the git blame/history more carefully. The Features.Replace('strict', '') line was introduced specifically to remove strict from the Features property. Let me check the earliest commits that touched this line.

Assistant: The commit history from the GitHub API isn't giving me enough detail on each commit to find the one that introduced the Features line. Let me look at the JonHanna commits, since they appeared in the earliest page and seem like the most likely author of enum arithmetic tests.

Assistant: That commit (dd36755) doesn't seem to be the one that introduced the Features line. Let me look at which commit actually added it by checking the earlier commit by JonHanna:

Assistant: Neither of those early JonHanna commits are the one that added the Features line. Let me look at the commit that specifically added the <Features> property to this csproj. The Features.Replace('strict', '') line must have been added when the repo-wide <Features>strict</Features> was introduced. Let me check who added that.

Assistant: Good question. Let me trace back the history of this line.

The <Features>$(Features.Replace('strict', '')</Features> line in Microsoft.CSharp.Tests.csproj exists to remove the strict feature from the compiler features for this test project. And yes, strict is set — it comes from the repo's root Directory.Build.props:

    <!-- Enables Strict mode for Roslyn compiler -->
    <Features>strict;nullablePublicOnly</Features>

So the flow is:

  1. Directory.Build.props sets <Features>strict;nullablePublicOnly</Features> for all projects in the repo.
  2. Microsoft.CSharp.Tests.csproj then strips strict out via $(Features.Replace('strict', '')) because the tests intentionally exercise operations that strict mode would reject (e.g., "Operator '-' cannot be applied to operands of type 'ushort' and 'EnumArithmeticTests.UInt16Enum'"), as the comment in the csproj explains.

The commit that added the Features.Replace line along with the EnumUnaryOperationTests.cs that needs it was [dd36755](https://...

This pull request was created from Copilot chat.

Copilot AI review requested due to automatic review settings April 14, 2026 05:02
Copilot AI review requested due to automatic review settings April 14, 2026 05:02
…s.csproj

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/6a912ada-d720-4d82-8766-8b90d754be25

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot April 14, 2026 05:05
Copilot AI changed the title [WIP] Fix malformed MSBuild property function call in project file Fix malformed MSBuild property function call in Microsoft.CSharp.Tests.csproj Apr 14, 2026
Copilot AI requested a review from MichalStrehovsky April 14, 2026 05:07
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @phil-allen-msft, @333fred
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an MSBuild property function syntax error in Microsoft.CSharp.Tests.csproj so the Features property is computed correctly (rather than silently evaluating to an empty string).

Changes:

  • Corrects the malformed $(Features.Replace(...)) call by adding the missing closing parenthesis, ensuring only strict is removed while preserving inherited features (e.g., nullablePublicOnly).

@jkotas jkotas merged commit dc7cee8 into main Apr 14, 2026
108 of 110 checks passed
@jkotas jkotas deleted the copilot/fix-malformed-msbuild-property-call branch April 14, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants