Repository navigation
Add MSBuild multithreaded build support to the CsWinRT tasks - #2671
Merged
Sergio Pedri (Sergio0694) merged 7 commits intoNov 26, 2026
Merged
Sergio Pedri (Sergio0694) merged 7 commits into
Sergio Pedri (Sergio0694) merged 7 commits into
Conversation
Sergio Pedri (Sergio0694)
requested a review
from Manodasan Wignarajah (manodasanW)
November 24, 2026 22:15
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Multi-target WinRT.Generator.Tasks as net472 and net10.0 and use the MSBuild multithreaded build APIs (MSBuildMultiThreadableTask, IMultiThreadableTask, TaskEnvironment) in all tasks. Require MSBuild 18.7 or later, the first version where ToolTask supports them. Ship both task assemblies in the NuGet package and select one by MSBuildRuntimeType. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A project reference to a multi-targeted project only builds the target framework compatible with the referencing project, so the net472 tasks were not built. Desktop MSBuild consumers load the net472 assembly, and Test_MultiThreadableTasks opens both, so explicitly reference each target framework. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A bare 'cl' was looked up by CreateProcess using the PATH of the MSBuild process rather than the environment table supplied by TaskEnvironment, so it failed when the compiler was only on the task's PATH under -mt. Add ProcessStartInfo.ResolveFileName, which searches the PATH of the start info for bare names, and use it before launching cl.exe. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ectory ToolTask passes the tool path to Process as is, so a relative ToolPath was resolved against the current directory of the shared MSBuild process, and failed under -mt. Override GetProcessStartInfo in all tool tasks to resolve the file name, enforce it with Test_MultiThreadableTasks, and document it. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sergio Pedri (Sergio0694)
force-pushed
the
user/sergiopedri/msbuild-multithreaded-tasks
branch
from
November 26, 2026 00:21
74b4edd to
b303234
Compare
TaskEnvironment.GetAbsolutePath leaves root-relative (\foo) and drive-relative (C:foo) paths unchanged, so Windows resolved them against the drive and directory of the MSBuild process rather than the project, which failed under -mt when the host was on another drive. Qualify these against the project drive or directory in TryGetAbsolutePath, and add unit tests for the path qualification. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sergio Pedri (Sergio0694)
force-pushed
the
user/sergiopedri/msbuild-multithreaded-tasks
branch
from
November 26, 2026 01:51
9c27760 to
0a2f0b7
Compare
Manodasan Wignarajah (manodasanW)
approved these changes
Nov 26, 2026
Sergio Pedri (Sergio0694)
enabled auto-merge (squash)
November 26, 2026 06:39
Sergio Pedri (Sergio0694)
deleted the
user/sergiopedri/msbuild-multithreaded-tasks
branch
November 26, 2026 06:46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add support for MSBuild multithreaded builds (
-mt) to all CsWinRT 3.0 build tasks, by multi-targetingWinRT.Generator.Tasksasnet472andnet10.0and using the real MSBuild multithreading APIs.Motivation
MSBuild 18.x can run tasks in-process in parallel (
-mt), but only tasks marked with[MSBuildMultiThreadableTask]opt in (the others run in a slower sidecar process). In this mode the process current directory and environment are no longer project-scoped, so tasks must not rely on them. TheMicrosoft.Build.*18.x packages that define these APIs only shipnet472andnet10.0assemblies, so the tasks can no longer targetnetstandard2.0.net472is still needed because Visual Studio andMSBuild.exerun tasks on .NET Framework, while thedotnetCLI runs them on .NET.Changes
src/WinRT.Generator.Tasks/: all six tasks are marked[MSBuildMultiThreadableTask]. The fiveToolTask-based tasks inheritIMultiThreadableTaskfromToolTask, whileGenerateCsWinRTStubExesimplements it directly and startscl.exefromTaskEnvironment.GetProcessStartInfo(). Every path a task touches itself is resolved withTaskEnvironment.GetAbsolutePath(via a newExtensions/TaskEnvironmentExtensions.cshelper).src/WinRT.Generator.Tasks/WinRT.Generator.Tasks.csproj: now targetsnet472;net10.0and referencesMicrosoft.Build.Utilities.Core18.7.1 (the first version whereToolTasksupports multithreaded builds) andPolySharp(new central package version insrc/Directory.Packages.props). Also setsPlatformTarget=AnyCPUand emitsSupportedOSPlatformonnet10.0.nuget/Microsoft.Windows.CsWinRT.targets: new_CsWinRTValidateMSBuildVersiontarget that fails early with a clear message when MSBuild is older than 18.7.nuget/Microsoft.Windows.CsWinRT.CsWinRTGen.targets,src/Directory.Build.props:CsWinRTGenTasksAssemblynow selects thenet10.0ornet472task assembly based on$(MSBuildRuntimeType).nuget/Microsoft.Windows.CsWinRT.nuspec,src/build.cmd,build/AzurePipelineTemplates/: ship, stage and sign both task assemblies (tools\net10.0\andtools\net472\).src/Tests/InteropGeneratorTest/: point at thenet10.0task assembly and addTest_MultiThreadableTasks, which checks that every task in both assemblies has the attribute andIMultiThreadableTask..github/: update the generator tasks section of the Copilot instructions and the interop generator skill.Notes
Test_ServerGCandTest_MultiThreadableTasks, and running a task with a relative path from a different current directory underdotnet msbuild -mt(net10.0) and the Visual StudioMSBuild.exe(net472). The pipelines and NuGet packing were not run.