Conversation
There was a problem hiding this comment.
Pull request overview
This PR standardizes repository usage of Microsoft.IO (from Microsoft.IO.Redist) by moving from framework-based compilation guards to a single feature flag and by using explicit type aliases (e.g., Path = Microsoft.IO.Path) to reduce ambiguity and unify call sites.
Changes:
- Replace assorted
NETFRAMEWORK/NET*conditional patterns withFEATURE_MSIOREDIST. - Introduce/adjust
Microsoft.IOtype aliases (Path,File,Directory, etc.) to make opt-in usage explicit. - Clean up/normalize
System.IOusings in a few test files.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Tasks/XamlTaskFactory/CommandLineGenerator.cs | Removes conditional Microsoft.IO import where it’s not needed. |
| src/Tasks.UnitTests/RoslynCodeTaskFactory_Tests.cs | Normalizes System.IO using placement and removes unused conditional aliasing. |
| src/Shared/TaskFactoryUtilities.cs | Switches to FEATURE_MSIOREDIST and aliases Microsoft.IO.File/Path for consistent usage. |
| src/Shared/FileSystem/WindowsFileSystem.cs | Uses FEATURE_MSIOREDIST to opt into Microsoft.IO.File.Exists. |
| src/Shared/FileMatcher.cs | Uses FEATURE_MSIOREDIST to alias Microsoft.IO.Path consistently. |
| src/MSBuild/XMake.cs | Uses FEATURE_MSIOREDIST and explicit aliases for Microsoft.IO filesystem types. |
| src/MSBuild.UnitTests/MSBuildServer_Tests.cs | Simplifies conditional IO usings to System.IO. |
| src/Framework/PathHelpers/AbsolutePath.cs | Uses FEATURE_MSIOREDIST to alias Microsoft.IO.Path for path helper functionality. |
| src/Build/Utilities/Utilities.cs | Moves Path selection under FEATURE_MSIOREDIST for consistency. |
| src/Build/Logging/TerminalLogger/TerminalLogger.cs | Uses FEATURE_MSIOREDIST to select Path implementation consistently. |
| src/Build/Instance/TaskFactories/AssemblyTaskFactory.cs | Uses FEATURE_MSIOREDIST to alias Microsoft.IO.Path. |
| src/Build/Evaluation/Expander/ArgumentParser.cs | Updates conditional compilation to FEATURE_MSIOREDIST for Microsoft.IO namespace import. |
| src/Build/Evaluation/Expander.cs | Uses FEATURE_MSIOREDIST to alias Microsoft.IO.Directory/Path while keeping System.IO baseline. |
| src/Build/BuildCheck/Checks/ExecCliBuildCheck.cs | Uses FEATURE_MSIOREDIST to alias Microsoft.IO.Path where enabled. |
| src/Build/BuildCheck/Checks/DoubleWritesCheck.cs | Uses FEATURE_MSIOREDIST to alias Microsoft.IO.Path where enabled. |
| src/Build/BackEnd/Shared/BuildRequestConfiguration.cs | Uses FEATURE_MSIOREDIST for span-based Microsoft.IO.Path operations on supported builds. |
Comments suppressed due to low confidence (1)
src/Build/BackEnd/Shared/BuildRequestConfiguration.cs:308
- Switching this guard to
FEATURE_MSIOREDISTchanges the compilation behavior forDotNetBuildSourceOnly.NETFramework builds (whereFEATURE_MSIOREDISTis not defined). In that configuration, the#elsebranch usesSystem.IO.Path.GetFileName(ProjectFullPath.AsSpan()), but the span overloads are not available on .NET Framework, causing a compile failure. Add an explicit#elif NETFRAMEWORKfallback that uses the string-based overload (or otherwise avoid span overloads when building netfx without Microsoft.IO.Redist).
#if FEATURE_MSIOREDIST
if (MemoryExtensions.Equals(Microsoft.IO.Path.GetFileName(ProjectFullPath.AsSpan()), "dirs.proj".AsSpan(), StringComparison.OrdinalIgnoreCase))
#else
if (MemoryExtensions.Equals(Path.GetFileName(ProjectFullPath.AsSpan()), "dirs.proj", StringComparison.OrdinalIgnoreCase))
#endif
| #if FEATURE_MSIOREDIST | ||
| using File = Microsoft.IO.File; | ||
| using Path = Microsoft.IO.Path; | ||
| #else | ||
| using System.IO; |
There was a problem hiding this comment.
FEATURE_MSIOREDIST is not defined for DotNetBuildSourceOnly .NETFramework builds, so this file will fall back to System.IO.Path. However, later in this file you call Path.IsPathFullyQualified(...) under #if NETFRAMEWORK || NET, which will not compile on .NET Framework when Path is System.IO.Path (no IsPathFullyQualified there). Update the conditional compilation around the IsPathFullyQualified usage (or provide a .NET Framework fallback implementation) so source-only .NETFramework builds compile without Microsoft.IO.Redist.
| #if FEATURE_MSIOREDIST | ||
| using Path = Microsoft.IO.Path; | ||
| #else | ||
| using System.IO; | ||
| #endif |
There was a problem hiding this comment.
When DotNetBuildSourceOnly is true on .NETFramework, FEATURE_MSIOREDIST is not defined and this file will use System.IO.Path. But later, ValidatePath calls Path.IsPathFullyQualified(...) under #if NETFRAMEWORK || NET, which won't compile on .NET Framework without Microsoft.IO.Redist. Narrow the guard to FEATURE_MSIOREDIST || NET (or add a .NET Framework fallback) so source-only netfx builds compile.
| #if FEATURE_MSIOREDIST | ||
| using Path = Microsoft.IO.Path; | ||
| #else | ||
| using System.IO; | ||
| #endif |
There was a problem hiding this comment.
With DotNetBuildSourceOnly on .NETFramework, FEATURE_MSIOREDIST is not defined so Path resolves to System.IO.Path. This file uses APIs like Path.GetRelativePath(...) (not available on .NET Framework), so the source-only .NETFramework build will fail to compile. Please either guard those API usages with #if FEATURE_MSIOREDIST and provide a fallback (e.g., via existing FileUtilities.MakeRelative), or keep Microsoft.IO.Path available for all .NETFramework builds where these APIs are needed.
| #if FEATURE_MSIOREDIST | ||
| using Path = Microsoft.IO.Path; | ||
| #else | ||
| using System.IO; | ||
| #endif |
There was a problem hiding this comment.
FEATURE_MSIOREDIST is disabled for DotNetBuildSourceOnly .NETFramework builds, which means this file will use System.IO.Path. However, later in this file Path.GetFullPath(fileBeingWritten, context.Data.ProjectFileDirectory) is used, and that overload does not exist on .NET Framework's System.IO.Path. Provide a netfx fallback when FEATURE_MSIOREDIST is off (e.g., route through FileUtilities.GetFullPath(..., currentDirectory, ...) or equivalent) so source-only netfx builds compile.
This reverts commit 6b7a28c.
This reverts commit 6b7a28c.
Reverts #13062 It causes regression in VS, see https://dev.azure.com/devdiv/DevDiv/_workitems/edit/2695509 for details. CC: @AR-May
Reverts dotnet#13062 It causes regression in VS, see https://dev.azure.com/devdiv/DevDiv/_workitems/edit/2695509 for details. CC: @AR-May
Fixes #13041
Context
At this moment we have multiple different patterns of using
Microsoft.IOnamespace fromMicrosoft.IO.Redist.Changes Made
Refactored
Microsoft.IOnamespace usage.Testing
unit tests