Skip to content

Support injecting the build tool via environment variables - #17094

Merged
ViktorHofer merged 1 commit into
dotnet:mainfrom
ViktorHofer:ViktorHofer/inject-buildtool-via-env
Jul 10, 2026
Merged

ViktorHofer merged 1 commit into
dotnet:mainfrom
ViktorHofer:ViktorHofer/inject-buildtool-via-env

Conversation

@ViktorHofer

Copy link
Copy Markdown
Member

Summary

Adds a _BuildToolPath / _BuildToolCommand environment-variable hook to InitializeBuildTool in both eng/common/tools.ps1 and eng/common/tools.sh.

When _BuildToolPath is set, InitializeBuildTool returns that path/command directly instead of resolving the in-proc $global:_BuildTool (PowerShell) / _InitializeBuildTool (bash) variable. Only Path and Command are consumed by the MSBuild function, so those are all that is injected.

Motivation

Orchestration scripts such as a two-stage bootstrapped build currently have to dot-source tools.ps1 / tools.sh in order to set the internal _BuildTool variable before invoking build.ps1 / build.sh. Dot-sourcing forces in-proc execution and leaks the toolset's dynamically-scoped variables into the caller (and into any child script the caller runs).

This hook lets those scripts invoke build.ps1 / build.sh out-of-process with a clean scope while still pointing MSBuild at a custom (e.g. freshly-bootstrapped) build tool, purely via environment variables.

Notes

  • No behavior change when _BuildToolPath is unset — the existing resolution path is unchanged.
  • dotnet/msbuild is the initial consumer (its cibuild_bootstrapped_msbuild scripts).

Add a _BuildToolPath / _BuildToolCommand environment-variable hook to
InitializeBuildTool in tools.ps1 and tools.sh. When _BuildToolPath is set,
InitializeBuildTool returns that path/command instead of resolving the in-proc
$global:_BuildTool / _InitializeBuildTool variable.

This lets orchestration scripts (e.g. a two-stage bootstrap build) run
build.ps1/build.sh out-of-process with a clean scope and still point MSBuild at
a custom build tool, without dot-sourcing tools.ps1/tools.sh to set the internal
variable.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 0ba1f12e-c9d7-4f5e-b31c-911fc21be955
Copilot AI review requested due to automatic review settings July 10, 2026 13:31

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.

Pull request overview

This PR adds an environment-variable hook to InitializeBuildTool so external orchestration scripts can invoke build.sh / build.ps1 out-of-process while still directing MSBuild to use a caller-specified build tool path + command.

Changes:

  • Add _BuildToolPath / _BuildToolCommand environment-variable support to InitializeBuildTool in tools.sh.
  • Add _BuildToolPath / _BuildToolCommand environment-variable support to InitializeBuildTool in tools.ps1.
Show a summary per file
File Description
eng/common/tools.sh Adds env-var injection path for the build tool initialization used by MSBuild.
eng/common/tools.ps1 Adds env-var injection path for the build tool initialization used by MSBuild.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment thread eng/common/tools.sh Resolved
Comment thread eng/common/tools.ps1 Resolved
@ViktorHofer
ViktorHofer enabled auto-merge (squash) July 10, 2026 13:37
@ViktorHofer
ViktorHofer merged commit c5269bb into dotnet:main Jul 10, 2026
9 of 10 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 13, 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