Repository navigation
Migrate GetPackageDirectory - #54444
Conversation
There was a problem hiding this comment.
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]+IMultiThreadableTaskwithTaskEnvironment.Fallbackdefault, and absolutizeAssetsFileWithAdditionalPackageFoldersbeforeLockFileCache.GetLockFile(mirrorsCheckForTargetInAssetsFile). - Absolutize each
PackageFoldersentry (pass-through for null/empty) beforeNuGetPackageResolver.CreateResolver, then use theout packageRootoverload to rewritePackageDirectorymetadata 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
left a comment
There was a problem hiding this comment.
Looks good! Left a few smaller comments :-)
jankratochvilcz
left a comment
There was a problem hiding this comment.
Trying to verify some of the comments to make sure the paths are what we think they are :-)
Fixes dotnet/msbuild#13868
Adds
[MSBuildMultiThreadableTask]+IMultiThreadableTaskand routes pathinputs through
TaskEnvironmentso the task works under MSBuild's worker-threadmodel (CWD ≠ project dir).
Changes
AssetsFileWithAdditionalPackageFoldersbeforeLockFileCache.GetLockFile(mirrors
CheckForTargetInAssetsFile).PackageFoldersentry beforeNuGetPackageResolver.CreateResolver.Null/empty entries pass through so NuGet's existing validation fires (no new
ArgumentExceptionfromGetAbsolutePath("")).PackageDirectoryoutput metadata via theout packageRootoverload — keeps[Output]byte-identical to pre-migration (no Sin 1).Compatibility
All 6 sins reviewed; none triggered. Two intentional drifts:
Strings.AssetsFilePathNotRootedis now unreachable from this caller (path isalways rooted before the check). No tests depend on it.
PackageFolders, the resolverpreviously returned
null(CWD probe failed); now it correctly finds thepackage 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.csPackageDirectoryMetadata_PreservesRelativeFolderShape_WhenInputIsRelative— Sin 1EmptyPackageFolderEntry_DoesNotThrow_AndValidFallbackResolves— Sin 6AbsolutePackageFolders_ProduceAbsoluteMetadata_AndDoNotLeakProjectDirectory— happy-path regression