Refactor FileUtilities.cs and add methods for absolute paths.#13079
Merged
AR-May merged 4 commits intodotnet:mainfrom Jan 21, 2026
Merged
Refactor FileUtilities.cs and add methods for absolute paths.#13079AR-May merged 4 commits intodotnet:mainfrom
AR-May merged 4 commits intodotnet:mainfrom
Conversation
d6f86d4 to
6362a96
Compare
AR-May
commented
Jan 21, 2026
AR-May
commented
Jan 21, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors file utility functions by moving several methods from Shared/FileUtilities.cs to a new Framework/FileUtilities.cs file in the FrameworkFileUtilities class. This enables support for AbsolutePath operations as referenced in PRs #12914 and #12868, since shared files cannot reference Framework types.
Changes:
- Created new
FrameworkFileUtilitiesclass insrc/Framework/FileUtilities.cswith methods for slash handling, path fixing, and trailing slash operations - Added new overloads for
AbsolutePathoperations includingEnsureTrailingSlash,EnsureNoTrailingSlash,NormalizePath,RemoveRelativeSegments, andFixFilePath - Updated 64 files across the codebase to call
FrameworkFileUtilitiesmethods instead ofFileUtilitiesmethods for the moved functions - Added
using Microsoft.Build.Framework;imports where needed and removed conditional compilation guards that are no longer necessary
Reviewed changes
Copilot reviewed 63 out of 63 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Framework/FileUtilities.cs | New file containing FrameworkFileUtilities class with moved utility methods and new AbsolutePath overloads |
| src/Framework/ErrorUtilities.cs | Changed FrameworkErrorUtilities from non-static to static class |
| src/Shared/FileUtilities.cs | Removed methods moved to FrameworkFileUtilities; updated remaining methods to call FrameworkFileUtilities |
| src/Shared/FileMatcher.cs | Updated to use FrameworkFileUtilities for directory separator characters |
| src/Shared/Modifiers.cs | Updated to use FrameworkFileUtilities methods for slash operations |
| src/Shared/FrameworkLocationHelper.cs | Added Framework namespace import and updated method calls |
| src/Shared/TempFileUtilities.cs | Added Framework namespace import and updated EnsureTrailingSlash call |
| src/MSBuildTaskHost/MSBuildTaskHost.csproj | Included both Framework and Shared FileUtilities files with appropriate Link names |
| src/MSBuild/XMake.cs | Updated FixFilePath calls to use FrameworkFileUtilities |
| src/MSBuild/CommandLine/CommandLineParser.cs | Updated method calls to FrameworkFileUtilities |
| src/Utilities/*.cs (7 files) | Updated method calls from FileUtilities to FrameworkFileUtilities |
| src/Tasks/*.cs (17 files) | Updated method calls from FileUtilities to FrameworkFileUtilities with Framework namespace imports |
| src/Build/*.cs (13 files) | Updated method calls to FrameworkFileUtilities; removed conditional #if NET guard in Toolset.cs |
| Test files (14 files) | Updated test assertions and helpers to use FrameworkFileUtilities |
Comments suppressed due to low confidence (2)
src/Tasks/GetSDKReferenceFiles.cs:649
- This foreach loop implicitly filters its target sequence - consider filtering the sequence explicitly using '.Where(...)'.
src/Shared/FileUtilities.cs:797 - These 'if' statements can be combined.
if (NativeMethodsShared.IsWindows && !FrameworkFileUtilities.EndsWithSlash(fullPath))
{
if (FileUtilitiesRegex.IsDrivePattern(fileSpec) ||
FileUtilitiesRegex.IsUncPattern(fullPath))
{
// append trailing slash if Path.GetFullPath failed to (this happens with drive-specs and UNC shares)
fullPath += Path.DirectorySeparatorChar;
}
}
JanProvaznik
approved these changes
Jan 21, 2026
Member
JanProvaznik
left a comment
There was a problem hiding this comment.
annoying that there are now both utilities but it's needed and a positive step in the broad refactor shared utilities goal
johnazule
pushed a commit
to johnazule/msbuild
that referenced
this pull request
Jan 22, 2026
…#13079) ### Context PRs dotnet#12914 and dotnet#12868 showed that we need to be able to fix and normalize `AbsolutePath`. Corresponding methods for strings live in `FileUtilities.cs` that is a Shared file and cannot reference Framework classes like `AbsolutePath`. ### Changes Made - Moved some related functions to FrameworkFileUtilities class. - Added the needed functions for `AbsolutePath` ### Testing unit tests
This was referenced Mar 11, 2026
This was referenced Mar 11, 2026
Open
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.
Context
PRs #12914 and #12868 showed that we need to be able to fix and normalize
AbsolutePath. Corresponding methods for strings live inFileUtilities.csthat is a Shared file and cannot reference Framework classes likeAbsolutePath.Changes Made
AbsolutePathTesting
unit tests