Fix malformed MSBuild property function call in Microsoft.CSharp.Tests.csproj#126864
Merged
Fix malformed MSBuild property function call in Microsoft.CSharp.Tests.csproj#126864
Conversation
…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
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
Contributor
|
Tagging subscribers to this area: @phil-allen-msft, @333fred |
This was referenced Apr 14, 2026
Open
Contributor
There was a problem hiding this comment.
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 onlystrictis removed while preserving inherited features (e.g.,nullablePublicOnly).
jkotas
approved these changes
Apr 14, 2026
333fred
approved these changes
Apr 14, 2026
jkoritzinsky
approved these changes
Apr 14, 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.
Microsoft.CSharp.Tests.csprojhad 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 theReplacefunction. This silently cleared all compiler features — includingnullablePublicOnlyfromDirectory.Build.props— rather than surgically removing onlystrict.Description
$(Features.Replace('strict', '')— MSBuild fails to parse as a property function; evaluates to"", stripping all features$(Features.Replace('strict', ''))— correctly evaluates to";nullablePublicOnly", preserving other features while only removingstrictThe
strictfeature 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: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 removestrict(the intended effect), but also unintentionally removesnullablePublicOnlyand any other features inherited from the repo-wideDirectory.Build.props(which sets<Features>strict;nullablePublicOnly</Features>).The fix is to add the missing closing parenthesis so the property function works correctly:
This will properly evaluate the
Replacecall, surgically removing onlystrictwhile preserving all other features likenullablePublicOnly.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:This line tries to remove
strictfrom the$(Features)property, but it's also missing a closing). Let me investigate whereFeatures=strictmight 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 ifFeatures=strictwas set somewhere.Let me look at the commit that introduced this line. Let me use
git logvia the blame/search approach.Assistant: Now I can see the full picture. Let me verify the
Directory.Build.propsline 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
Featuresline.Assistant: Let me look at the git blame/history more carefully. The
Features.Replace('strict', '')line was introduced specifically to removestrictfrom 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
Featuresline. 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
Featuresline. 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
Featuresline. Let me look at the commit that specifically added the<Features>property to this csproj. TheFeatures.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 inMicrosoft.CSharp.Tests.csprojexists to remove thestrictfeature from the compiler features for this test project. And yes,strictis set — it comes from the repo's rootDirectory.Build.props:So the flow is:
Directory.Build.propssets<Features>strict;nullablePublicOnly</Features>for all projects in the repo.Microsoft.CSharp.Tests.csprojthen stripsstrictout via$(Features.Replace('strict', ''))because the tests intentionally exercise operations thatstrictmode 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.Replaceline along with theEnumUnaryOperationTests.csthat needs it was [dd36755](https://...This pull request was created from Copilot chat.