Migrate Unzip task to use TaskEnvironment API#13109
Merged
Conversation
Contributor
|
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. |
Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com>
Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Migrate Unzip task to use TaskEnvironment API
Migrate Unzip task to use TaskEnvironment API
Jan 26, 2026
Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR migrates the Unzip task to use the TaskEnvironment API for thread-safe path resolution, enabling safe execution in MSBuild's multithreaded environment. This follows the established pattern from PR #12914 that migrated other file I/O tasks (Copy, Delete, MakeDir, RemoveDir, Touch).
Changes:
- Added
IMultiThreadableTaskinterface and[MSBuildMultiThreadableTask]attribute to enable multithreaded execution - Replaced process-global
Path.GetFullPath()calls with thread-safeTaskEnvironment.GetAbsolutePath() - Updated all 17 test cases to provide
TaskEnvironmentinstances viaTaskEnvironmentHelper.CreateForTest()
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Tasks/Unzip.cs | Added multithreadable task support and migrated three path resolution calls (destination folder, source file, extracted file path) to use TaskEnvironment API while preserving zip-slip security validation |
| src/Tasks.UnitTests/Unzip_Tests.cs | Updated all 17 Unzip task instantiations to include TaskEnvironment property initialization |
JanProvaznik
approved these changes
Jan 26, 2026
Member
|
blocked by #13120 for correctness |
… Path.GetFullPath in Extract method Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com>
JanProvaznik
approved these changes
Feb 2, 2026
JanProvaznik
approved these changes
Feb 2, 2026
SimaTian
approved these changes
Feb 5, 2026
JanProvaznik
added a commit
to JanProvaznik/msbuild
that referenced
this pull request
Feb 25, 2026
### Context Migrates the Unzip task to use the `TaskEnvironment` API for thread-safe path resolution, following the pattern established in dotnet#12914. This enables the task to run safely in MSBuild's multithreaded execution model. ### Changes Made - Add `IMultiThreadableTask` interface and `[MSBuildMultiThreadableTask]` attribute to `Unzip` class - Add `TaskEnvironment` property - Replace `Path.GetFullPath()` with `TaskEnvironment.GetAbsolutePath()` for: - Destination folder creation (inside try block for proper error handling) - Source file path resolution (wrapped in try-catch to continue processing on invalid paths) - Keep `Path.GetFullPath()` in the `Extract` method for DirectoryInfo-based paths where it's cleaner - Update all unit tests to provide `TaskEnvironmentHelper.CreateForTest()` when instantiating the task ### Testing - All 14 Unzip unit tests pass - Updated all test instantiations to provide `TaskEnvironmentHelper.CreateForTest()` ### Notes - The `GetAbsolutePath` calls are wrapped in try-catch blocks to handle exceptions from invalid paths gracefully - The zip-slip exploit protection continues to use `Path.GetFullPath()` on `DirectoryInfo.FullName` as it's cleaner for paths that are already absolute <!-- START COPILOT CODING AGENT SUFFIX --> <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > Migrate the Unzip task to use TaskEnvironment API based on the pattern used here: dotnet#12914 > > Make sure to preserve correctness, performance and that the tests pass </details> <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com>
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.
Context
Migrates the Unzip task to use the
TaskEnvironmentAPI for thread-safe path resolution, following the pattern established in #12914. This enables the task to run safely in MSBuild's multithreaded execution model.Changes Made
IMultiThreadableTaskinterface and[MSBuildMultiThreadableTask]attribute toUnzipclassTaskEnvironmentpropertyPath.GetFullPath()withTaskEnvironment.GetAbsolutePath()for:Path.GetFullPath()in theExtractmethod for DirectoryInfo-based paths where it's cleanerTaskEnvironmentHelper.CreateForTest()when instantiating the taskTesting
TaskEnvironmentHelper.CreateForTest()Notes
GetAbsolutePathcalls are wrapped in try-catch blocks to handle exceptions from invalid paths gracefullyPath.GetFullPath()onDirectoryInfo.FullNameas it's cleaner for paths that are already absoluteOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.