Skip to content

unify temp folder logic and simplify cleanup#12688

Merged
JanProvaznik merged 6 commits intodotnet:mainfrom
JanProvaznik:unify-temp-behavior
Oct 23, 2025
Merged

unify temp folder logic and simplify cleanup#12688
JanProvaznik merged 6 commits intodotnet:mainfrom
JanProvaznik:unify-temp-behavior

Conversation

@JanProvaznik
Copy link
Member

@JanProvaznik JanProvaznik commented Oct 21, 2025

partially addresses #12543

Context

followup to #11948 and 728984d

  • we need cleanup of orphaned inline task dlls but we don't have a stable place for them

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.

@JanProvaznik JanProvaznik marked this pull request as ready for review October 22, 2025 08:45
Copilot AI review requested due to automatic review settings October 22, 2025 08:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@JanProvaznik JanProvaznik changed the title cleanup temp folder unify temp folder logic and simplify cleanup Oct 22, 2025
@JanProvaznik JanProvaznik self-assigned this Oct 22, 2025
@JanProvaznik JanProvaznik merged commit ad915a4 into dotnet:main Oct 23, 2025
10 checks passed
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.

3 participants