Skip to content

Migrate GetPackageDirectory - #54444

Merged
AlesProkop merged 6 commits into
dotnet:mainfrom
AlesProkop:GetPackageDirectory
Jun 3, 2026
Merged

AlesProkop merged 6 commits into
dotnet:mainfrom
AlesProkop:GetPackageDirectory

Conversation

@AlesProkop

Copy link
Copy Markdown
Member

Fixes dotnet/msbuild#13868

Adds [MSBuildMultiThreadableTask] + IMultiThreadableTask and routes path
inputs through TaskEnvironment so the task works under MSBuild's worker-thread
model (CWD ≠ project dir).

Changes

  • Absolutize AssetsFileWithAdditionalPackageFolders before LockFileCache.GetLockFile
    (mirrors CheckForTargetInAssetsFile).
  • Absolutize each PackageFolders entry before NuGetPackageResolver.CreateResolver.
    Null/empty entries pass through so NuGet's existing validation fires (no new
    ArgumentException from GetAbsolutePath("")).
  • Capture caller's original folder shapes and substitute them back into the
    PackageDirectory output metadata via the out packageRoot overload — keeps
    [Output] byte-identical to pre-migration (no Sin 1).

Compatibility

All 6 sins reviewed; none triggered. Two intentional drifts:

  • Strings.AssetsFilePathNotRooted is now unreachable from this caller (path is
    always rooted before the check). No tests depend on it.
  • Under multithreaded MSBuild with a relative PackageFolders, the resolver
    previously returned null (CWD probe failed); now it correctly finds the
    package and the original-prefix substitution restores the caller's shape.
    This is the point of the migration.

Tests

New: test/Microsoft.NET.Build.Tasks.Tests/GivenAGetPackageDirectoryMultiThreading.cs

  • PackageDirectoryMetadata_PreservesRelativeFolderShape_WhenInputIsRelative — Sin 1
  • EmptyPackageFolderEntry_DoesNotThrow_AndValidFallbackResolves — Sin 6
  • AbsolutePackageFolders_ProduceAbsoluteMetadata_AndDoNotLeakProjectDirectory — happy-path regression

@AlesProkop AlesProkop self-assigned this May 26, 2026
@AlesProkop
AlesProkop marked this pull request as ready for review May 28, 2026 06:38
Copilot AI review requested due to automatic review settings May 28, 2026 06:38

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

Migrates GetPackageDirectory to MSBuild's multi-threaded task model by adding IMultiThreadableTask support and routing path inputs through TaskEnvironment.GetAbsolutePath, so the task resolves package folders relative to the project directory rather than the process CWD. To preserve byte-identical [Output] shape, the task captures the caller's original folder strings and substitutes them back in when the resolver matched an internally-absolutized folder.

Changes:

  • Add [MSBuildMultiThreadableTask] + IMultiThreadableTask with TaskEnvironment.Fallback default, and absolutize AssetsFileWithAdditionalPackageFolders before LockFileCache.GetLockFile (mirrors CheckForTargetInAssetsFile).
  • Absolutize each PackageFolders entry (pass-through for null/empty) before NuGetPackageResolver.CreateResolver, then use the out packageRoot overload to rewrite PackageDirectory metadata back to the caller's original prefix.
  • New tests cover relative-shape preservation, empty-folder pass-through, and absolute-folder non-contamination from TaskEnvironment.ProjectDirectory.

Reviewed changes

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

File Description
src/Tasks/Microsoft.NET.Build.Tasks/GetPackageDirectory.cs Implements IMultiThreadableTask, absolutizes paths via TaskEnvironment, and restores original folder prefixes in PackageDirectory output metadata.
test/Microsoft.NET.Build.Tasks.Tests/GivenAGetPackageDirectoryMultiThreading.cs New tests for relative-shape preservation (Sin 1), empty-entry pass-through (Sin 6), and absolute-folder happy-path regression.

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

Looks good! Left a few smaller comments :-)

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

Trying to verify some of the comments to make sure the paths are what we think they are :-)

@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 roll 🤘🎸

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.

Migrate GetPackageDirectory to MultiThreaded

4 participants