dotnet / dotnet/msbuild

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

Open
#10,239 2 comments 0 reactions 0 assignees View on GitHub
Area: Documentation bug triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 6h
Merged PRs (30d)
139

Description

### 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:
```xml

Foo*;Bar*

```

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
```xml

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

```

### 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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.