Skip to content

Adds validation to throw MSB4259 when property references contain leading or trailing whitespace outside of conditions.#13076

Merged
JanProvaznik merged 11 commits intodotnet:mainfrom
huulinhnguyen-dev:dev/huulinhnguyen/issue_error_for_whitespace_in_property
Jan 30, 2026
Merged

Adds validation to throw MSB4259 when property references contain leading or trailing whitespace outside of conditions.#13076
JanProvaznik merged 11 commits intodotnet:mainfrom
huulinhnguyen-dev:dev/huulinhnguyen/issue_error_for_whitespace_in_property

Conversation

@huulinhnguyen-dev
Copy link
Copy Markdown
Contributor

Fixes #12352 Adds validation to throw MSB4259 when property references contain leading or trailing whitespace outside of conditions.

Context

Property references with whitespace like $( Foo ) silently expand to empty string instead of throwing error MSB4259. The validation in Scanner.cs only works for Conditions, not for general property expansion.

Changes Made

  • Added whitespace validation in Expander.cs for regular property path (line ~1385)
  • Updated unit test PropertySimpleSpaced to expect MSB4259 error instead of empty string
  • Added test for property functions with whitespace in parameters (should still work)

Testing

  • PropertyWithWhitespace_ShouldThrowError: verifies $( Foo ), $( Foo), $(Foo ) throw MSB4259
  • PropertyFunctionWithWhitespaceInParameters_ShouldSucceed: verifies $(Foo.StartsWith( 'bar' )) still works

Notes

@huulinhnguyen-dev huulinhnguyen-dev marked this pull request as ready for review January 23, 2026 02:28
Copy link
Copy Markdown
Member

@JanProvaznik JanProvaznik left a comment

Choose a reason for hiding this comment

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

a couple of questions to clarify if this is mergeable

Comment thread src/Build.UnitTests/Evaluation/Expander_Tests.cs
Comment thread src/Build.UnitTests/Evaluation/Expander_Tests.cs Outdated
@huulinhnguyen-dev huulinhnguyen-dev force-pushed the dev/huulinhnguyen/issue_error_for_whitespace_in_property branch from bee934d to 29a86ed Compare January 26, 2026 06:37
Comment thread src/Build/Resources/Strings.resx Outdated
Comment thread src/Build.UnitTests/Evaluation/Expander_Tests.cs Outdated
Comment thread documentation/wiki/ChangeWaves.md Outdated
@JanProvaznik JanProvaznik merged commit fa41623 into dotnet:main Jan 30, 2026
9 checks passed
@davidwengier
Copy link
Copy Markdown
Member

So I can't open any Razor projects in VS main, because of a space in a targets file in my Program Files (x86) folder, that was last modified in 2019. This is a little disruptive :)

JanProvaznik added a commit to JanProvaznik/msbuild that referenced this pull request Feb 3, 2026
…tain leading or trailing whitespace outside of conditions. (dotnet#13076)"

This reverts commit fa41623.
JanProvaznik added a commit that referenced this pull request Feb 3, 2026
…ces contain leading or trailing whitespace outside of conditions. (#13184)
Copilot AI pushed a commit that referenced this pull request Feb 3, 2026
…ces contain leading or trailing whitespace outside of conditions. (#13184)
colincmac added a commit to colincmac/grpc that referenced this pull request Feb 3, 2026
…perty function (VS 18.5 Insiders / MSBuild)

Fixes grpc#41548

Grpc.Tools 2.76.0 currently contains a property function invocation in:

build/_protobuf/Google.Protobuf.Tools.props
that triggers the following error:

Unexpected space at position "3" of property reference "$( [System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)../../tools) )". Did you forget to remove a space?

This PR removes the invalid whitespace from that property reference so that projects consuming Grpc.Tools load and build correctly under the newer MSBuild validation.

Reference: dotnet/msbuild PR introducing the validation/error: dotnet/msbuild#13076
JanProvaznik added a commit to JanProvaznik/msbuild that referenced this pull request Feb 25, 2026
…eferences contain leading or trailing whitespace outside of conditions. (dotnet#13184)
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.

Whitespace in property names not issuing error

4 participants