Add System.Uri::EscapeDataString to MSBuild property function allowlist#12572
Merged
YuliiaKovalova merged 2 commits intomainfrom Nov 20, 2025
Merged
Conversation
Contributor
|
Hello @@copilot, I noticed that you’re changing an .swr file or any file under src/Package/MSBuild.VSSetup.. Please make sure to validate this change by an experimental VS insertion. This is accomplished by pushing to an exp/* branch, which requires write permissions to this repo. |
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Instead of hacking with UriBuilder.Path, I think it would be better to add
Add System.Uri::EscapeDataString to MSBuild property function allowlist
Sep 27, 2025
[System.Uri]::EscapeDataString to the allowlist at the MSBuild side.
javiercn
approved these changes
Sep 27, 2025
YuliiaKovalova
approved these changes
Nov 20, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds System.Uri to the MSBuild property function allowlist, enabling developers to use EscapeDataString and UnescapeDataString methods for proper URI encoding in MSBuild projects without workarounds.
Key changes:
- Adds
System.Urito the allowed static methods in MSBuild - Includes a unit test verifying
EscapeDataStringfunctionality
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Build/Resources/Constants.cs | Adds System.Uri to the AvailableStaticMethods allowlist |
| src/Build.UnitTests/Evaluation/IntrinsicFunctionOverload_Tests.cs | Adds test for System.Uri::EscapeDataString functionality |
Comments suppressed due to low confidence (2)
src/Build/Resources/Constants.cs:152
- Field 'defaultSolutionWrapperProjectToolsVersion' can be 'readonly'.
internal static string defaultSolutionWrapperProjectToolsVersion = MSBuildConstants.CurrentToolsVersion;
src/Build/Resources/Constants.cs:147
- Field 'defaultFallbackToolsVersion' can be 'readonly'.
internal static string defaultFallbackToolsVersion = MSBuildConstants.CurrentToolsVersion;
This was referenced Nov 21, 2025
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.
Resolves #12571
This PR adds
System.Uri::EscapeDataString(andUnescapeDataString) to the MSBuild property function allowlist, enabling developers to properly escape URI components in MSBuild projects without needing to resort to workarounds withUriBuilder.Path.Problem
Previously, developers who needed to URL-encode strings in MSBuild had to use workarounds like manipulating
UriBuilder.Path, which is not semantically correct and error-prone. TheSystem.Uri::EscapeDataStringmethod is the standard .NET approach for encoding URI data components.Solution
Added
System.Urito theAvailableStaticMethodsallowlist inConstants.cs, which enables all static methods on theSystem.Uriclass includingEscapeDataStringandUnescapeDataString.Usage
Safety
System.Uri::EscapeDataStringis a pure function with no side effects, making it completely safe for use during project evaluation. It follows the same security model as other allowed static methods likeSystem.StringandSystem.Convert.Testing
UriBuilderfunctionality remains unaffectedThis change provides a clean, semantically correct way to handle URI encoding in MSBuild without breaking any existing functionality.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.