Migrate GenerateDepsFile to IMultiThreadableTask#53950
Open
SimaTian wants to merge 1 commit intodotnet:mainfrom
Open
Migrate GenerateDepsFile to IMultiThreadableTask#53950SimaTian wants to merge 1 commit intodotnet:mainfrom
SimaTian wants to merge 1 commit intodotnet:mainfrom
Conversation
Implements IMultiThreadableTask to enable safe multi-threaded execution: - Added [MSBuildMultiThreadableTask] attribute - Added TaskEnvironment property with NETFRAMEWORK polyfill - Absolutize ProjectPath at task level before passing to DependencyContextBuilder - Moved AssetsFilePath and RuntimeGraphPath absolutization into WriteDepsFile - Use AbsolutePath.OriginalValue for FilesWritten output to preserve relativity Addresses all 3 AR-May findings from PR dotnet#52936: 1. ProjectPath absolutization: Now absolutized at ExecuteCore level via TaskEnvironment.GetAbsolutePath, passes .Value (absolute) to DependencyContextBuilder 2. Cleanliness: AssetsFilePath and RuntimeGraphPath absolutization moved into WriteDepsFile where consumed 3. Output fidelity: FilesWritten uses AbsolutePath.OriginalValue to preserve user-supplied relative paths Added comprehensive behavioral tests in GivenAGenerateDepsFileMultiThreading.cs: - OutputRelativityIsPreserved: Verifies FilesWritten preserves relative paths - ProjectPathIsAbsolutized: Ensures ProjectPath is absolutized before use - DecoyCwdDoesNotAffectPathResolution: Validates CWD independence - CrossThreadEnvVarIsolation: Tests environment variable isolation - MultiProcessParity: Confirms identical output with/without TaskEnvironment - ConcurrentExecutionProducesCorrectResults: Parallel execution test Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Migrates GenerateDepsFile to support MSBuild multithreaded execution by implementing IMultiThreadableTask, using TaskEnvironment for path resolution, and adding unit tests intended to validate correctness under concurrent execution / non-default working directories.
Changes:
- Add
[MSBuildMultiThreadableTask]and implementIMultiThreadableTaskonGenerateDepsFile, includingTaskEnvironmenthandling. - Absolutize
ProjectPath/DepsFilePathbefore writing and moveAssetsFilePath/RuntimeGraphPathabsolutization to point-of-use. - Add a new multithreading-focused unit test suite for
GenerateDepsFile.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs | Adds IMultiThreadableTask support and adjusts path handling for multithread-safe execution and output fidelity. |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenAGenerateDepsFileMultiThreading.cs | Adds behavioral/concurrency tests for GenerateDepsFile in multithreaded / CWD-sensitive scenarios. |
Comment on lines
+324
to
+326
| AbsolutePath absoluteProjectPath = TaskEnvironment?.GetAbsolutePath(ProjectPath) ?? new AbsolutePath(Path.GetFullPath(ProjectPath)); | ||
| AbsolutePath absoluteDepsFilePath = TaskEnvironment?.GetAbsolutePath(DepsFilePath) ?? new AbsolutePath(Path.GetFullPath(DepsFilePath)); | ||
| WriteDepsFile(absoluteProjectPath, absoluteDepsFilePath, TaskEnvironment); |
Comment on lines
+10
to
+14
| using Microsoft.Build.Utilities; | ||
| using Newtonsoft.Json; | ||
| using Newtonsoft.Json.Linq; | ||
| using Xunit; | ||
| using Task = System.Threading.Tasks.Task; |
| using Task = System.Threading.Tasks.Task; | ||
|
|
||
| namespace Microsoft.NET.Build.Tasks.UnitTests | ||
| { |
Comment on lines
+66
to
+74
| string projectPath = depsJson.SelectToken("targets..TestApp/1.0.0")?.Parent?.Parent?.Parent?.Parent? | ||
| .SelectToken("libraries['TestApp/1.0.0'].path")?.ToString(); | ||
|
|
||
| // The path stored should be absolute because we absolutized ProjectPath | ||
| if (!string.IsNullOrEmpty(projectPath)) | ||
| { | ||
| Path.IsPathRooted(projectPath).Should().BeTrue( | ||
| "ProjectPath should be absolutized internally even when passed as relative"); | ||
| } |
This was referenced Apr 17, 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.
Migrates \GenerateDepsFile\ to support \IMultiThreadableTask.
Changes
Addresses AR-May findings from #52936
Supersedes
Part of the split of stuck merge-group PR #52936. This is the 2-of-5 split for \GenerateDepsFile.