Skip to content

Use Microsoft.IO.Redist in Framework FileUtilities/NativeMethods on net472 (#13078)#13428

Open
sachinsharma3191 wants to merge 6 commits intodotnet:mainfrom
sachinsharma3191:dev/13078-microsoft-io-fileutilities
Open

Use Microsoft.IO.Redist in Framework FileUtilities/NativeMethods on net472 (#13078)#13428
sachinsharma3191 wants to merge 6 commits intodotnet:mainfrom
sachinsharma3191:dev/13078-microsoft-io-fileutilities

Conversation

@sachinsharma3191
Copy link

@sachinsharma3191 sachinsharma3191 commented Mar 21, 2026

Summary

Addresses #13078 by replacing custom Win32 GetFullPath / GetCurrentDirectory paths in Microsoft.Build.Framework with Microsoft.IO.Redist when FEATURE_MSIOREDIST is enabled (net472).

Changes

  • Remove FEATURE_LEGACY_GETCURRENTDIRECTORY and FEATURE_LEGACY_GETFULLPATH from Directory.BeforeCommon.targets for all net4* targets.
  • FileUtilities.GetFullPath: use NewPath.GetFullPath when FEATURE_MSIOREDIST; otherwise System.IO.Path.GetFullPath.
  • NativeMethods.GetCurrentDirectory: use Microsoft.IO.Directory.GetCurrentDirectory() when FEATURE_MSIOREDIST; remove unused kernel32 imports and Win32 helpers removed with the legacy path code.
  • Add Microsoft.IO.Redist package reference to Microsoft.Build.Framework.csproj (conditional on FeatureMSIORedist, consistent with other projects).
  • Tests: FileUtilities_Tests expectation aligned with non-legacy behavior; Expander path-too-long cases gated with #if NETFRAMEWORK.

Notes

  • MSBuildTaskHost (net35) keeps its own utilities and is unchanged.
  • Validation: Microsoft.Build.Framework builds for net10.0 / netstandard2.0 locally; full net472 + tests should be run on Windows per repo guidance.

Fixes #13078

@sachinsharma3191
Copy link
Author

@dotnet-policy-service agree

sachinsharma3191 added a commit to sachinsharma3191/msbuild that referenced this pull request Mar 22, 2026
sachinsharma3191 added a commit to sachinsharma3191/msbuild that referenced this pull request Mar 22, 2026
@sachinsharma3191 sachinsharma3191 force-pushed the dev/13078-microsoft-io-fileutilities branch 2 times, most recently from b5b1ffe to 72bfc27 Compare March 22, 2026 01:38
…3078)

Add Microsoft.IO.Redist to Microsoft.Build.Framework for net4* targets. FileUtilities.GetFullPath and NativeMethods.GetCurrentDirectory use Microsoft.IO.Path and Microsoft.IO.Directory when FEATURE_MSIOREDIST is set.

Legacy Win32 GetCurrentDirectory/GetFullPathName are not enabled by default: the FEATURE_LEGACY_* compile constants are preserved only as comments in Directory.BeforeCommon.targets, while the DllImports and helpers remain available behind FEATURE_LEGACY_* preprocessor guards for opt-in builds.

Adjust Framework unit tests with a NETFRAMEWORK gate for path-too-long expander cases.
@sachinsharma3191 sachinsharma3191 force-pushed the dev/13078-microsoft-io-fileutilities branch from 72bfc27 to 96d5dfb Compare March 22, 2026 01:44
@sachinsharma3191 sachinsharma3191 marked this pull request as ready for review March 23, 2026 03:18
When Path.GetFullPath throws PathTooLongException, rethrow instead of
falling back to Microsoft.IO.Path.GetFullPath. The latter may not throw
for the same path, causing Regress451057_ExitGracefullyIfPathNameIsTooLong
tests to fail (they expect the task to return false, not succeed with a
long path).

Made-with: Cursor
…ths as invalid

- Paths with leading/trailing whitespace: Microsoft.IO.Path.GetFullPath may
  trim them, causing incorrect resolution. Treat as invalid (CanNotResolveHintPathWithSpace).
- Paths >= 260 chars: GetFullPath throws PathTooLongException on legacy
  Windows. Treat as invalid so callers skip NormalizePath and handle
  gracefully (Regress314573_VeryLongPaths).

Made-with: Cursor
@sachinsharma3191 sachinsharma3191 force-pushed the dev/13078-microsoft-io-fileutilities branch from b4db326 to ccc36bd Compare March 23, 2026 05:09
@AR-May AR-May self-assigned this Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use Microsoft.IO.Redist in FileUtilities on net472 instead of custom methods

2 participants