Instead of hacking with UriBuilder.Path, I think it would be better to add [System.Uri]::EscapeDataString to the allowlist at the MSBuild side.
Originally posted by @KalleOlaviNiemitalo in dotnet/sdk#51039 (comment)
We should allow this method on the set of known functions. It's available across framework and modern .NET.