Repository navigation
migrate GZipCompress - #54996
migrate GZipCompress#54996
Conversation
There was a problem hiding this comment.
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
GZipCompressas multi-threadable ([MSBuildMultiThreadableTask],IMultiThreadableTask) and introduced aTaskEnvironmentproperty (defaulting toTaskEnvironment.Fallback). - Resolved
OutputDirectoryand input file paths againstTaskEnvironment.ProjectDirectoryand 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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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));
Fixes dotnet/msbuild#14166
Context
Migrates the
GZipCompressMSBuild 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 viaTaskEnvironmentrather than the process CWD.Changes Made
GZipCompresswith[MSBuildMultiThreadableTask]and implementedIMultiThreadableTask, adding aTaskEnvironmentproperty defaulting toTaskEnvironment.Fallback.OutputDirectoryviaTaskEnvironment.GetAbsolutePath(...)and used it forDirectory.CreateDirectoryand for buildingoutputFullPathused byFile.Exists,File.GetLastWriteTimeUtc, andFile.Create.Parallel.Forloop, sinceTaskEnvironmentis not thread-safe; usedPath.GetFullPath(TaskEnvironment.GetAbsolutePath(itemSpec))to canonicalize and match the previousGetMetadata("FullPath")semantics.file.GetMetadata("FullPath")andFile.OpenRead(file.ItemSpec)with the pre-resolved absolute path so input reads no longer depend on the process CWD.OutputDirectoryform for the emittedCompressedFilesitem specs and log messages to avoid absolutized paths leaking into task output.Testing
Microsoft.NET.Sdk.BlazorWebAssembly.Tasks.csproj— 0 errors.GZipCompressTest:Compresses_ResolvingRelativePathsAgainstProjectDirectory_NotProcessCurrentDirectory— asserts inputs/outputs resolve underTaskEnvironment.ProjectDirectory(not the process CWD), the.gzround-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.