msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

[Bug]: MSBuild automatically escapes all my strings for me with seemingly no way to have it not do that?

Open EdLichtman opened this issue 1 month ago • 2 comments

Issue Description

I need to add the following to an ItemGroup: Foo..%2a;Bar..%2a

This is because if I put Foo..;Bar.., I'm intending to split 2 regex expressions into a list. But MSBuild thinks it's a WildCard.

However, if I try to replace * with %2A, MSBuild automatically converts my semi-colon to %3b.

Therefore, when I add my property to an ItemGroup to split on semi-colon, it becomes one single entry with Foo.;Bar.

Steps to Reproduce

I have a propertygroup I'm building with wildcards:

<PropertyGroup>
  <MyProperty>Foo*;Bar*</MyProperty>
</PropertyGroup>

I want to use my property to filter PackageReferences, which are not inherently Files, so the WildCard syntax won't work if I try to Include them.

So I've decided to turn my WildCard into Regex

<PropertyGroup>
  <MyProperty>Foo*;Bar*</MyProperty>
  <MyProperty>$(MyProperty.Replace(".","\.").Replace("*",".*").Replace("?",".").Replace("*", "%2A"))</MyProperty>
</PropertyGroup>

Expected Behavior

What I expect to see is: MyProperty="Foo..%2A;Bar..%2A"

Actual Behavior

What I instead see is: MyProperty="Foo..%2a%3bBar..%2a"

Analysis

No response

Versions & Configurations

MSBuild version 17.8.3+195e7f5a3 for .NET 17.8.3.51904

EdLichtman avatar Jun 13 '24 16:06 EdLichtman