Skip to content

migrate GZipCompress - #54996

Merged
AlesProkop merged 5 commits into
dotnet:mainfrom
AlesProkop:migrate-gz-ip-compress
Jul 1, 2026
Merged

AlesProkop merged 5 commits into
dotnet:mainfrom
AlesProkop:migrate-gz-ip-compress

Conversation

@AlesProkop

Copy link
Copy Markdown
Member

Fixes dotnet/msbuild#14166

Context

Migrates the GZipCompress MSBuild task to the multithreaded execution model so it no longer depends on the shared process working directory. Under multithreaded MSBuild, tasks must resolve paths against their own project directory via TaskEnvironment rather than the process CWD.

Changes Made

  • Decorated GZipCompress with [MSBuildMultiThreadableTask] and implemented IMultiThreadableTask, adding a TaskEnvironment property defaulting to TaskEnvironment.Fallback.
  • Absolutized OutputDirectory via TaskEnvironment.GetAbsolutePath(...) and used it for Directory.CreateDirectory and for building outputFullPath used by File.Exists, File.GetLastWriteTimeUtc, and File.Create.
  • Pre-resolved every input path on the calling thread before the Parallel.For loop, since TaskEnvironment is not thread-safe; used Path.GetFullPath(TaskEnvironment.GetAbsolutePath(itemSpec)) to canonicalize and match the previous GetMetadata("FullPath") semantics.
  • Replaced file.GetMetadata("FullPath") and File.OpenRead(file.ItemSpec) with the pre-resolved absolute path so input reads no longer depend on the process CWD.
  • Preserved the original relative OutputDirectory form for the emitted CompressedFiles item specs and log messages to avoid absolutized paths leaking into task output.

Testing

  • Built Microsoft.NET.Sdk.BlazorWebAssembly.Tasks.csproj — 0 errors.
  • Added and ran focused tests in GZipCompressTest:
    • Compresses_ResolvingRelativePathsAgainstProjectDirectory_NotProcessCurrentDirectory — asserts inputs/outputs resolve under TaskEnvironment.ProjectDirectory (not the process CWD), the .gz round-trips, and the output item spec stays relative.
    • Compresses_TwoInstancesWithDifferentProjectDirectories_AreIndependent — asserts two instances with different project directories compress to their own directories, proving per-instance resolution.
    • Result: 2 passed, 0 failed.

Copilot AI review requested due to automatic review settings June 26, 2026 06:13
@AlesProkop
AlesProkop requested a review from a team as a code owner June 26, 2026 06:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 GZipCompress MSBuild task in the Blazor WASM SDK to MSBuild’s multi-threaded task execution model by resolving input/output paths via TaskEnvironment instead of relying on the process current working directory, and adds regression tests to ensure relative path resolution is per-project-instance.

Changes:

  • Marked GZipCompress as multi-threadable ([MSBuildMultiThreadableTask], IMultiThreadableTask) and introduced a TaskEnvironment property (defaulting to TaskEnvironment.Fallback).
  • Resolved OutputDirectory and input file paths against TaskEnvironment.ProjectDirectory and used absolute paths for file IO inside the parallel loop.
  • Added tests validating relative-path resolution against the project directory and independence across two task instances with different project directories.

Reviewed changes

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

File Description
test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/GZipCompressTest.cs Adds focused tests ensuring GZipCompress resolves relative paths via TaskEnvironment.ProjectDirectory and remains instance-isolated.
src/BlazorWasmSdk/Tasks/GZipCompress.cs Updates task to be MSBuild-multi-threadable and to use TaskEnvironment for path resolution, avoiding reliance on process CWD.

@jankratochvilcz jankratochvilcz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a minor test comment, then I'm good to go :-) I'm not 100% about the raw arrays vs. just using LINQ which could make the code a bit less brittle, just flagging this to make sure it's an intentional decision due to e.g., performance

@OvesN OvesN left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, I think it is correct but you can doble check if file.GetMetadata("FullPath") trully returns the same value as Path.GetFullPath(TaskEnvironment.GetAbsolutePath(FilesToCompress[i].ItemSpec));

@jankratochvilcz jankratochvilcz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's go!

@AlesProkop
AlesProkop merged commit 57c2fa6 into dotnet:main Jul 1, 2026
25 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 6, 2026
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.

[Multithreaded] Migrate GZipCompress in SDK

4 participants