Skip to content

Migrate GetRestoreProjectReferencesTask to the multithreadable model - #7536

Merged
zivkan merged 2 commits into
NuGet:devfrom
OvesN:veronikao/migrate-GetRestoreProjectReferencesTask-to-mt
Jul 1, 2026
Merged

zivkan merged 2 commits into
NuGet:devfrom
OvesN:veronikao/migrate-GetRestoreProjectReferencesTask-to-mt

Conversation

@OvesN

@OvesN OvesN commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes dotnet/msbuild#14183

What & why

MSBuild 18.6 can run tasks in-process during multithreaded builds (dotnet build -mt). GetRestoreProjectReferencesTask resolved each project reference with Path.GetFullPath, which depends on the process current directory — incorrect when the task shares a long-lived process. This migrates it to the multithreadable model.

Changes

  • Mark the task [MSBuildMultiThreadableTask]; implement IMultiThreadableTask on the .NET (SDK) build.
  • Resolve the reference path via TaskEnvironment.GetAbsolutePath (project directory) instead of Path.GetFullPath (current directory). The .NET Framework build keeps the original behavior.
  • Add the [MSBuildMultiThreadableTask] attribute polyfill for the .NET Framework build (separate commit) so the marker compiles against the in-box MSBuild facade.
  • Add a net10.0 test asserting the reference path resolves against the project directory, not the current directory.

OvesN and others added 2 commits July 1, 2026 01:37
…rk build

The [MSBuildMultiThreadableTask] marker attribute only exists in Microsoft.Build.Framework
18.6 and later. The .NET (SDK) build of NuGet's MSBuild tasks gets it from the package, but
the .NET Framework build compiles against the in-box MSBuild reference assemblies, which do
not contain the type. This adds a self-defined compatibility shim (guarded by #if NETFRAMEWORK,
in the Microsoft.Build.Framework namespace) so the shared task source can apply the marker
without conditional compilation at every task. MSBuild detects the attribute by namespace and
name only, so the shim is recognized by 18.6+ hosts and ignored by older ones.

This is a prerequisite for migrating relative-path-resolving restore tasks to the
multithreadable execution model.

Co-authored-by: Copilot <[email protected]>
Mark the task with [MSBuildMultiThreadableTask] and, on the .NET (SDK) build, implement
IMultiThreadableTask. The project reference path is now resolved with TaskEnvironment.GetAbsolutePath
(rooted at the project directory) instead of Path.GetFullPath (rooted at the process current
directory), so the task is correct when MSBuild runs it in-process during multithreaded builds.
The .NET Framework build keeps the original Path.GetFullPath behavior. Adds a net10.0 test asserting
the reference path resolves against the project directory rather than the current directory.

Co-authored-by: Copilot <[email protected]>
@OvesN
OvesN requested a review from a team as a code owner June 30, 2026 23:41
@OvesN
OvesN requested review from donnie-msft and zivkan June 30, 2026 23:41
@dotnet-policy-service dotnet-policy-service Bot added the Community PRs created by someone not in the NuGet team label Jun 30, 2026
@OvesN

OvesN commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@nkolev92 @zivkan ptal

@zivkan zivkan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@OvesN in the future, please use/keep our PR template

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community PRs created by someone not in the NuGet team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Multithreaded] Migrate GetRestoreProjectReferencesTask in NuGet

2 participants