Skip to content

Mark GetRestoreProjectStyleTask as MSBuild-multithreadable - #7537

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

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

Conversation

@OvesN

@OvesN OvesN commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes dotnet/msbuild#14184

What

Mark GetRestoreProjectStyleTask with [MSBuildMultiThreadableTask] so MSBuild can run it in-process during multithreaded builds (dotnet build -mt).

Why attribute-only is safe

The task reads its item/property inputs and produces the project style outputs. Call-chain audit (Execute -> BuildTasksUtility.GetProjectRestoreStyle -> ProjectHasPackagesConfigFile -> GetPackagesConfigFilePath):

  • The only file-system access is File.Exists(Path.Combine(MSBuildProjectDirectory, "packages.config")). MSBuildProjectDirectory is the [Required], always-absolute $(MSBuildProjectDirectory), so the probe never resolves against the current directory.
  • No environment variables, no ProcessStartInfo, no Path.GetFullPath, no mutable static state.

The [MSBuildMultiThreadableTask] attribute polyfill for the .NET Framework build is included as a separate commit.

OvesN and others added 2 commits July 1, 2026 01:49
…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]>
The task reads its item/property inputs and produces the project style. Its only file-system access
(probing for packages.config via BuildTasksUtility.GetProjectRestoreStyle ->
ProjectHasPackagesConfigFile -> GetPackagesConfigFilePath) is File.Exists on
Path.Combine(MSBuildProjectDirectory, ...). MSBuildProjectDirectory is the [Required] always-absolute
$(MSBuildProjectDirectory), so the probe never resolves against the current directory. There is no
environment-variable, ProcessStartInfo, Path.GetFullPath, or mutable-static usage, so the task is
already thread-safe and needs only the [MSBuildMultiThreadableTask] marker - no
IMultiThreadableTask/TaskEnvironment migration.

Co-authored-by: Copilot <[email protected]>
@OvesN
OvesN requested a review from a team as a code owner June 30, 2026 23:51
@OvesN
OvesN requested review from kartheekp-ms and nkolev92 June 30, 2026 23:51
@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 please use/keep the repo's PR template in the future

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 GetRestoreProjectStyleTask in NuGet

2 participants