Skip to content

Migrate Microsoft.DotNet.Build.Tasks.Installers to multithreaded MSBuild - #17513

Merged
ViktorHofer merged 1 commit into
dotnet:mainfrom
ViktorHofer:mt-safe-subset-4
Sep 9, 2026
Merged

ViktorHofer merged 1 commit into
dotnet:mainfrom
ViktorHofer:mt-safe-subset-4

Conversation

@ViktorHofer

Copy link
Copy Markdown
Member

Fourth safe subset of #17381. Opts the installer tasks into multithreaded MSBuild so they resolve paths against the project directory instead of the process current directory.

  • CreateChangelogFile, CreateControlFile, CreateDebPackage, CreateMD5SumsFile, CreateRpmPackage, GenerateMacOSDistributionFile, StabilizeWixFileId: resolve paths at the point of use. Log messages keep the original user-supplied path.
  • CreateWixBuildWixpack: the resolved working directory is threaded through the helper chain rather than each helper re-reading the raw property. MSBuildTask0002 is suppressed in the two places where the temp root is only the parent of a freshly generated unique name, so it is never shared between concurrent tasks.
  • ExecWithRetries: forwards TaskEnvironment to the nested Exec. MSBuild only injects it into tasks it instantiates itself, so without this a relative WorkingDirectory would resolve against the shared node's current directory.
  • CreateLightCommandPackageDrop: not opted in. Most of its execution lives in CreateWixCommandPackageDropBase, which still passes raw paths to File/Directory APIs. It implements IMultiThreadableTask without the attribute so it still receives TaskEnvironment for the path resolution it does do — routing keys off the attribute alone, so the interface cannot opt it in by accident. Tracked by Annotate Arcade MSBuild tasks with [MSBuildMultiThreadableTask] to avoid TaskHost marshalling in -mt builds #17378.

Validation

Microsoft.DotNet.Build.Tasks.Installers builds with 0 warnings. The Microsoft.Build.TaskAuthoring.Analyzer rules are errors for these tasks once they opt in, so every path flowing into file I/O is checked by the compiler. Verified the analyzer is actually active for this project by temporarily reverting one call site and confirming it fails with MSBuildTask0003.

Opts the deb/rpm/macOS/wixpack tasks into [MSBuildMultiThreadableTask] and
resolves every path that reaches file I/O through TaskEnvironment, so they no
longer depend on the process current directory.

- CreateChangelogFile, CreateControlFile, CreateDebPackage, CreateMD5SumsFile,
  CreateRpmPackage, GenerateMacOSDistributionFile, StabilizeWixFileId: resolve
  output/input paths at the point of use.
- CreateWixBuildWixpack: thread the resolved working directory through the
  helper chain instead of reading the raw property, and suppress MSBuildTask0002
  where the temp root is only a parent for a freshly generated unique name.
- ExecWithRetries: forward TaskEnvironment to the nested Exec instance, which
  MSBuild does not inject into task-created children.
- CreateLightCommandPackageDrop: not opted in; most of its work lives in
  CreateWixCommandPackageDropBase, which still passes raw paths. It implements
  IMultiThreadableTask only to receive TaskEnvironment. Tracked by
  dotnet#17378.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: be19d794-fe4f-43fe-9e6e-f6e6b13ec6e7
Copilot AI lite review requested due to automatic review settings September 8, 2026 19:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The tasks correctly opt into multithreaded routing and consistently resolve file I/O paths via TaskEnvironment without introducing new unchecked null-path or raw-path I/O in the modified regions.

Review tier: Lite
Findings: None

What changed in this PR

This PR migrates several Microsoft.DotNet.Build.Tasks.Installers MSBuild tasks to be safe for MSBuild’s in-proc multi-threaded execution (-mt) by opting into [MSBuildMultiThreadableTask] and resolving all file I/O paths via TaskEnvironment so relative paths bind to the project directory rather than the shared node process directory.

Changes:

  • Annotated the targeted installer tasks with [MSBuildMultiThreadableTask] and implemented IMultiThreadableTask with an injected TaskEnvironment property.
  • Updated file/directory/process call sites to use TaskEnvironment.GetAbsolutePath(...) (and threaded AbsolutePath through helper chains where needed, notably in CreateWixBuildWixpack).
  • Ensured nested Exec usage in ExecWithRetries inherits the outer task’s TaskEnvironment for correct WorkingDirectory resolution.
File Description
src/​Microsoft.DotNet.Build.Tasks.Installers/​src/​StabilizeWixFileId.cs Opts into multithreaded MSBuild and resolves input/output XML paths via TaskEnvironment.
src/​Microsoft.DotNet.Build.Tasks.Installers/​src/​GenerateMacOSDistributionFile.cs Opts into multithreaded MSBuild and resolves template/output paths via TaskEnvironment.
src/​Microsoft.DotNet.Build.Tasks.Installers/​src/​ExecWithRetries.cs Opts into multithreaded MSBuild and forwards TaskEnvironment into the nested Exec instance.
src/​Microsoft.DotNet.Build.Tasks.Installers/​src/​CreateWixBuildWixpack.cs Opts into multithreaded MSBuild; resolves/threads working directory and related file I/O paths using TaskEnvironment/AbsolutePath.
src/​Microsoft.DotNet.Build.Tasks.Installers/​src/​CreateRpmPackage.cs Opts into multithreaded MSBuild and resolves script/payload/output paths via TaskEnvironment.
src/​Microsoft.DotNet.Build.Tasks.Installers/​src/​CreateMD5SumsFile.cs Opts into multithreaded MSBuild and resolves input/output paths via TaskEnvironment.
src/​Microsoft.DotNet.Build.Tasks.Installers/​src/​CreateLightCommandPackageDrop.cs Explicitly does not opt into routing; keeps IMultiThreadableTask only for TaskEnvironment injection and resolves select paths for local I/O.
src/​Microsoft.DotNet.Build.Tasks.Installers/​src/​CreateDebPackage.cs Opts into multithreaded MSBuild and resolves control/data/output paths via TaskEnvironment.
src/​Microsoft.DotNet.Build.Tasks.Installers/​src/​CreateControlFile.cs Opts into multithreaded MSBuild and resolves output path via TaskEnvironment.
src/​Microsoft.DotNet.Build.Tasks.Installers/​src/​CreateChangelogFile.cs Opts into multithreaded MSBuild and resolves output path via TaskEnvironment.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ViktorHofer
ViktorHofer enabled auto-merge (squash) September 9, 2026 12:12
@ViktorHofer
ViktorHofer merged commit 7c67cae into dotnet:main Sep 9, 2026
12 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants