Implement IMultiThreadableTask for Move task#13108
Conversation
|
Hello @@copilot, I noticed that you’re changing an .swr file or any file under src/Package/MSBuild.VSSetup.. Please make sure to validate this change by an experimental VS insertion. This is accomplished by pushing to an exp/* branch, which requires write permissions to this repo. |
…solution Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com>
Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This pull request implements the IMultiThreadableTask interface for the Move task, enabling thread-safe execution in parallel build scenarios by replacing process-global Path.GetFullPath() calls with thread-safe TaskEnvironment.GetAbsolutePath(). This mirrors the changes made in PR #12914 for Copy, Delete, MakeDir, RemoveDir, and Touch tasks.
Changes:
- Modified Move task to implement IMultiThreadableTask and use TaskEnvironment for thread-safe path resolution
- Updated Move task tests to initialize TaskEnvironment for test execution
- Maintained backward compatibility by using OriginalValue for logging user-visible paths
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Tasks/Move.cs | Added IMultiThreadableTask interface, TaskEnvironment property, and converted MoveFileWithLogging and MakeWriteableIfReadOnly to accept AbsolutePath instead of string |
| src/Tasks.UnitTests/Move_Tests.cs | Added TaskEnvironment initialization to 20 Move task instantiations in test methods |
…g behavior Co-authored-by: AR-May <67507805+AR-May@users.noreply.github.com>
Co-authored-by: AR-May <67507805+AR-May@users.noreply.github.com>
Co-authored-by: AR-May <67507805+AR-May@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Jan Provazník <janprovaznik@microsoft.com> Co-authored-by: AR-May <67507805+AR-May@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Jan Provazník <janprovaznik@microsoft.com> Co-authored-by: AR-May <67507805+AR-May@users.noreply.github.com>
Context
Mirrors PR #12914 which migrated Copy, Delete, MakeDir, RemoveDir, and Touch tasks to use the thread-safe task API.
Path.GetFullPath()uses process-global CWD state which is unsafe when tasks run in parallel.TaskEnvironment.GetAbsolutePath()provides thread-safe path resolution via the task's execution context.Changes Made
src/Tasks/Move.cs:
[MSBuildMultiThreadableTask]attribute andIMultiThreadableTaskinterfaceTaskEnvironmentpropertyMoveFileWithLoggingandMakeWriteableIfReadOnlyto acceptAbsolutePathinstead ofstringTaskEnvironment.GetAbsolutePath()inExecute(), with calls placed inside the try block using nullableAbsolutePath?to preserve original error handling behavior (log error and continue with other inputs)sourceFile?.OriginalValue ?? sourceSpecforLockCheck.GetLockedFileMessagecall to safely handle null sourceFile in catch blocksrc/Tasks.UnitTests/Move_Tests.cs:
TaskEnvironmentHelper.CreateForTest()to all 20 Move task instantiationsTesting
All 18 applicable Move tests pass. 5 tests skipped (Windows/.NET Framework only).
Notes
Pattern matches existing implementations in Copy.cs, Delete.cs, MakeDir.cs, RemoveDir.cs, Touch.cs. The
GetAbsolutePathcalls are placed inside the try block (similar to Delete.cs) to ensure that any ArgumentException from null/empty paths is caught and logged, allowing the task to continue processing remaining files. The null-coalescing pattern forLockCheck.GetLockedFileMessageis consistent with the approach used in Delete.cs and MakeDir.cs.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.