Skip to content

Annotate trivial Nuget.Build.Tasks for multithreadable MSBuild execution - #7509

Merged
zivkan merged 1 commit into
NuGet:devfrom
JanProvaznik:dev-janprovaznik-multithreadable-restore-tasks
Jul 1, 2026
Merged

zivkan merged 1 commit into
NuGet:devfrom
JanProvaznik:dev-janprovaznik-multithreadable-restore-tasks

Conversation

@JanProvaznik

@JanProvaznik JanProvaznik commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Bug

Fixes: addresses the trivial case of part 3 NuGet/Home#14958

Description

These tasks are stateless so they can be used in multithreaded msbuild execution without changes.

polyfill the attribute to net472 where we're not consuming the new MSBuild API

on top of #7508

PR Checklist

  • [x ] Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@JanProvaznik
JanProvaznik requested a review from a team as a code owner June 25, 2026 14:02
@dotnet-policy-service dotnet-policy-service Bot added the Community PRs created by someone not in the NuGet team label Jun 25, 2026
@JanProvaznik

Copy link
Copy Markdown
Contributor Author

@nkolev92 @zivkan ptal

@nkolev92

Copy link
Copy Markdown
Member

Probably fine, need to merge the other first.

Comment thread Directory.Packages.props Outdated
MSBuild 18.6 can run tasks in-process during parallel builds (dotnet build -mt /
dotnet restore). Tasks opt in by carrying the [MSBuildMultiThreadableTask] marker
attribute (Microsoft.Build.Framework). This applies the marker to the 12 NuGet
restore tasks that are already thread-safe: they only read MSBuild item inputs
and produce outputs, with no current-working-directory, environment-variable,
ProcessStartInfo, or mutable-static usage. Tasks that resolve relative paths
(e.g. GetRestoreProjectReferencesTask, GetRestoreSolutionProjectsTask) are
intentionally left out; they need the TaskEnvironment migration first.

To avoid conditional compilation at every task, a self-defined compatibility shim
of the attribute is added for the .NET Framework build only
(Common/MSBuildMultiThreadableTaskAttribute.cs, guarded by #if NETFRAMEWORK). The
.NET (SDK) build uses the real attribute from the Microsoft.Build.Framework
18.6.3 package. MSBuild detects this attribute by namespace and name only
(ignoring the defining assembly), so the shim is recognized by 18.6+ hosts and
ignored by older ones. The shim is also compiled into NuGet.Build.Tasks.Pack
because it shares GetProjectTargetFrameworksTask.

Multithreaded mode is currently experimental and CLI-only; Visual Studio still
runs tasks out of process, so the marker is a safe no-op there today.

Tasks marked: GetRestoreDotnetCliToolsTask, GetProjectTargetFrameworksTask,
GetRestorePackageReferencesTask, GetCentralPackageVersionsTask,
GetRestorePackageDownloadsTask, GetRestoreFrameworkReferencesTask,
GetRestoreNuGetAuditSuppressionsTask, GetRestorePrunePackageReferencesTask,
CheckForDuplicateNuGetItemsTask, NuGetMessageTask, GetGlobalPropertyValueTask,
GetReferenceNearestTargetFrameworkTask.

Reference: https://learn.microsoft.com/visualstudio/msbuild/update-task-multithreaded

Part of NuGet/Home#14958.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JanProvaznik
JanProvaznik force-pushed the dev-janprovaznik-multithreadable-restore-tasks branch from c595edd to a87a270 Compare July 1, 2026 08:57
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.

3 participants