unify temp folder logic and simplify cleanup#12688
Merged
JanProvaznik merged 6 commits intodotnet:mainfrom Oct 23, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors MSBuild's temporary folder management to ensure proper cleanup and unify behavior across platforms. The changes address issues with temporary file accumulation by implementing lazy initialization and automatic cleanup on process exit.
Key Changes:
- Unified temporary folder creation across .NET and .NET Framework with platform-specific implementations
- Implemented lazy, thread-safe initialization with automatic cleanup registration
- Removed obsolete process-specific subdirectory logic for inline task assemblies
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Shared/TempFileUtilities.cs | Core refactoring: changed from nullable string to Lazy for thread-safe initialization, added ProcessExit cleanup handler, unified temp folder creation across platforms |
| src/Shared/TaskFactoryUtilities.cs | Removed process-specific temp directory creation and cleanup methods (CreateProcessSpecificTemporaryTaskDirectory, CleanCurrentProcessInlineTaskDirectory) |
| src/Build/BackEnd/BuildManager/BuildManager.cs | Removed explicit call to CleanCurrentProcessInlineTaskDirectory() since cleanup is now automatic |
| src/UnitTests.Shared/TestEnvironment.cs | Added FileUtilities.ClearTempFileDirectory() calls to ensure cached temp directory is refreshed when test environment changes temp paths |
| src/Tasks.UnitTests/*.cs | Removed manual cleanup calls to CleanCurrentProcessInlineTaskDirectory() and assertion checking for specific subdirectory path |
rainersigwald
approved these changes
Oct 23, 2025
This was referenced Oct 23, 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.
partially addresses #12543
Context
followup to #11948 and 728984d
Changes Made
unify logic for .NET across OSs
also temporary folder name for Framework
lazy synchronized creation/initialization
delete on process exit
clean up code for multithreaded inline task factories
Testing
existing tests
Notes
Why delete on process exit?
Alternative1: Delete by explicit call.
TaskHosts and project nodes may also use temp directory and they each create their own since they're different processes without shared statics. Only the main node as a logical endbuild point (counterpoint: perhaps project and taskhost nodes have also a logical place for this, and I just did not put enough effort in finding it).
Alternative2: Communicating to the main node where we created all the temps for other processes so main can delete all. Seems overengineered and would be major changes.
Cleanup is best effort with no retries.