Skip to content

Migrate ZipDirectory task to TaskEnvironment API#13110

Merged
JanProvaznik merged 3 commits intomainfrom
copilot/migrate-zipdirectory-task
Feb 5, 2026
Merged

Migrate ZipDirectory task to TaskEnvironment API#13110
JanProvaznik merged 3 commits intomainfrom
copilot/migrate-zipdirectory-task

Conversation

Copy link
Contributor

Copilot AI commented Jan 26, 2026

Context

Follows PR #12914 pattern. DirectoryInfo/FileInfo internally use Path.GetFullPath() which relies on process-global current working directory—not thread-safe when tasks run in parallel. The TaskEnvironment.GetAbsolutePath() API provides thread-safe path resolution using the task's execution context.

Changes Made

ZipDirectory.cs

  • Implement IMultiThreadableTask, add [MSBuildMultiThreadableTask] attribute
  • Add TaskEnvironment property
  • Use TaskEnvironment.GetAbsolutePath() to resolve paths, then create DirectoryInfo/FileInfo with the absolute path
  • Keep BuildEngine3.Yield()/Reacquire() calls (still needed for concurrency control)

ZipDirectory_Tests.cs

  • Set TaskEnvironment = TaskEnvironmentHelper.CreateForTest() on all test instances

Testing

All 9 ZipDirectory tests pass.

Notes

Preserves existing behavior including error handling flow where exceptions during zip creation log an error and return via !Log.HasLoggedErrors. Uses .FullName in error messages to match original behavior.

Original prompt

Migrate the ZipDirectory task to use TaskEnvironment API based on the pattern used here: #12914

Make sure to preserve correctness, performance and that the tests pass


💡 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.

@dotnet-policy-service
Copy link
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>
Copilot AI changed the title [WIP] Migrate ZipDirectory task to use TaskEnvironment API Migrate ZipDirectory task to TaskEnvironment API Jan 26, 2026
Copilot AI requested a review from JanProvaznik January 26, 2026 10:04
Copy link
Member

@JanProvaznik JanProvaznik left a comment

Choose a reason for hiding this comment

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

@copilot address comments and review your approach makes sense, we want a minimal refactor just using the absolutepaths where we would use ItemSpecs

… use DirectoryInfo/FileInfo with AbsolutePath

Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 26, 2026

@copilot address comments and review your approach makes sense, we want a minimal refactor just using the absolutepaths where we would use ItemSpecs

All review comments addressed in 4e09489. The approach is now minimal: use TaskEnvironment.GetAbsolutePath() for path resolution, then create DirectoryInfo/FileInfo with the absolute path, keeping the original structure with Yield/Reacquire.

@JanProvaznik JanProvaznik requested a review from SimaTian January 26, 2026 10:38
@JanProvaznik
Copy link
Member

blocked by #13120

@JanProvaznik JanProvaznik marked this pull request as ready for review February 2, 2026 09:07
Copilot AI review requested due to automatic review settings February 2, 2026 09:07
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 migrates the ZipDirectory task to use the TaskEnvironment API for thread-safe path resolution, following the pattern established in PR #12914. The changes enable the task to safely execute in parallel when MSBuild's multithreading is enabled by replacing process-global Path.GetFullPath() calls with thread-safe TaskEnvironment.GetAbsolutePath().

Changes:

  • Modified ZipDirectory task to implement IMultiThreadableTask and use TaskEnvironment API for thread-safe path resolution
  • Updated all 4 test cases to initialize TaskEnvironment property with test helper

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Tasks/ZipDirectory.cs Added IMultiThreadableTask interface, MSBuildMultiThreadableTask attribute, TaskEnvironment property, and thread-safe path resolution using TaskEnvironment.GetAbsolutePath()
src/Tasks.UnitTests/ZipDirectory_Tests.cs Updated all 4 ZipDirectory test instances to initialize TaskEnvironment property using TaskEnvironmentHelper.CreateForTest()

@JanProvaznik JanProvaznik merged commit f65ec6f into main Feb 5, 2026
15 checks passed
@JanProvaznik JanProvaznik deleted the copilot/migrate-zipdirectory-task branch February 5, 2026 15:24
JanProvaznik added a commit to JanProvaznik/msbuild that referenced this pull request Feb 25, 2026
### Context

Follows PR dotnet#12914 pattern. `DirectoryInfo`/`FileInfo` internally use
`Path.GetFullPath()` which relies on process-global current working
directory—not thread-safe when tasks run in parallel. The
`TaskEnvironment.GetAbsolutePath()` API provides thread-safe path
resolution using the task's execution context.

### Changes Made

**ZipDirectory.cs**
- Implement `IMultiThreadableTask`, add `[MSBuildMultiThreadableTask]`
attribute
- Add `TaskEnvironment` property
- Use `TaskEnvironment.GetAbsolutePath()` to resolve paths, then create
`DirectoryInfo`/`FileInfo` with the absolute path
- Keep `BuildEngine3.Yield()`/`Reacquire()` calls (still needed for
concurrency control)

**ZipDirectory_Tests.cs**
- Set `TaskEnvironment = TaskEnvironmentHelper.CreateForTest()` on all
test instances

### Testing

All 9 ZipDirectory tests pass.

### Notes

Preserves existing behavior including error handling flow where
exceptions during zip creation log an error and return via
`!Log.HasLoggedErrors`. Uses `.FullName` in error messages to match
original behavior.

<!-- START COPILOT CODING AGENT SUFFIX -->



<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> Migrate the ZipDirectory 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 -->
---

💡 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](https://gh.io/copilot-coding-agent-tips) in the docs.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: JanProvaznik <25267098+JanProvaznik@users.noreply.github.com>
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.

4 participants