Skip to content

[release/10.0.4xx] Source code updates from dotnet/msbuild - #7061

Merged
lewing merged 5 commits into
release/10.0.4xxfrom
darc-release/10.0.4xx-61956e16-48c7-4c04-9a0c-a02d585a7edd
Jun 5, 2026
Merged

lewing merged 5 commits into
release/10.0.4xxfrom
darc-release/10.0.4xx-61956e16-48c7-4c04-9a0c-a02d585a7edd

Conversation

@dotnet-maestro

@dotnet-maestro dotnet-maestro Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Note

This is a codeflow update. It may contain both source code changes from
the source repo
as well as dependency updates. Learn more here.

This pull request brings the following source code changes

From https://github.com/dotnet/msbuild

Diff the source with this PR branch
darc vmr diff --name-only https://github.com/dotnet/msbuild:f14c0d56b54b895512e18d6d40a7589fc0ec5d9a..https://github.com/dotnet/dotnet:darc-release/10.0.4xx-61956e16-48c7-4c04-9a0c-a02d585a7edd

@dotnet-maestro

dotnet-maestro Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team June 5, 2026 02:15
@JanProvaznik

Copy link
Copy Markdown
Member

failure otnet-unified-build (VMR Vertical Build Windows_x64):

##[error]src\msbuild\eng\BootStrapMsBuild.targets(243,5): error : (NETCORE_ENGINEERING_TELEMETRY=Build) Install-scripts was not executed successfully.

rerunning

@JanProvaznik
JanProvaznik enabled auto-merge (squash) June 5, 2026 08:44
@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team June 5, 2026 08:46
@JanProvaznik

Copy link
Copy Markdown
Member

hm rerun didn't help, copilot diagnosed as bad path quoting in msbuild targets, uncovered intermittently

…tCoreTask

Fixes bootstrap SDK acquisition failing when DotNetRoot contains a space
(e.g. C:\Program Files\dotnet). The PowerShell -File <scriptPath> and
-InstallDir <dir> arguments were unquoted, so PowerShell parsed
-File C:\Program and failed with "Install-scripts was not executed
successfully" (BootStrapMsBuild.targets(243,5)) on the VMR Windows legs.

Co-authored-by: Copilot <[email protected]>
@JanProvaznik

Copy link
Copy Markdown
Member

Added fix commit: quote the bootstrap dotnet-install invocation

Commit 782bde4 quotes the script path and install dir in InstallDotNetCoreTask so paths with spaces work:

  string scriptArgs = IsWindows
-     ? $"-NoProfile -ExecutionPolicy Bypass -File {scriptPath} -Version {Version} -InstallDir {InstallDir}"
-     : $"{scriptPath} --version {Version} --install-dir {InstallDir}";
+     ? $"-NoProfile -ExecutionPolicy Bypass -File \"{scriptPath}\" -Version {Version} -InstallDir \"{InstallDir}\""
+     : $"\"{scriptPath}\" --version {Version} --install-dir \"{InstallDir}\"";

Note: this is the VMR copy under src/msbuild. The durable fix should also land in dotnet/msbuild (src/MSBuild.Bootstrap.Utils/Tasks/InstallDotNetCoreTask.cs), otherwise the next forward-flow will revert it.

Root-cause analysis — how & why this went wrong

Symptom

Windows VMR legs fail with:

src\msbuild\eng\BootStrapMsBuild.targets(243,5): error : Install-scripts was not executed successfully.

That generic message is all the console shows because InstallDotNetCoreTask.LogEventsFromTextOutput logs the script output as low-importance messages (hidden at -verbosity minimal).

The real error (from the inner msbuild\Build.binlog, failing build 2992647)

Windows PowerShell
Processing -File 'C:\Program' failed because the file does not have a '.ps1' extension.

AcquireSdk runs:

powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:\Program Files\dotnet\dotnet-install.ps1 -Version 10.0.300 -InstallDir ...

The -File value is unquoted, so PowerShell sees -File C:\Program, rejects it, returns a non-zero exit code, and the task reports the generic failure. This bug is latent since dotnet/msbuild#10282 (Jul 2024) — SetupScriptsExecutionSettings() has never quoted the path.

Why it surfaced now — yes, the install path changed

The trigger is the value of $(DotNetRoot) (which feeds DotNetInstallScriptRootPath). Comparing the two builds' MSBuild.Bootstrap binlogs:

Build DotNetRoot AcquireSdk result
2992333 (Windows ✅) D:\a\_work\1\s\.dotnet\ — repo-local, no space dotnet-install ran, "Installed version is 10.0.300", success
2992647 (Windows ❌) C:\Program Files\dotnet\ — global, has a space -File C:\Program → parse error → failure

DotNetRoot is provided by Arcade and points at the SDK location used for the build. It flipped from the repo-local .dotnet (space-free) to the machine-global C:\Program Files\dotnet (with a space). The unquoted-path bug only bites when that path contains a space — so the path change is precisely what turned the dormant bug active.

Why it looked intermittent

InstallDotNetCoreTask.Execute() early-returns when InstallDir\sdk\<version> already exists, so it only runs the broken PowerShell command on a clean install dir. Note the msbuild source was identical between the passing (Jun 4 19:35) and failing (Jun 5 03:07) builds — none of the commits in between touch msbuild — confirming this was an environment/SDK-location change, not a code regression in that window. Likewise, this PR's source range (f69fa2f→f14c0d5: ToolTask/NodeLauncher/analyzers/loc) does not touch the bootstrap path; it's just the right open msbuild-flow PR to carry the fix.

Net

…rap install

The previous quoting fix exposed a second defect: InstallDir ends with a
directory separator ($(ArtifactsBinDir)bootstrap\core\), so the quoted
`-InstallDir "...\core\"` had its trailing `\"` escape the closing quote
on Windows, corrupting the path to `...\core"` (dotnet-install reported
"doesn't have write access to the installation root" / "Illegal characters
in path").

Trim trailing separators (root-preserving) before quoting. Validated locally
against powershell.exe using the same ToolTask process invocation.

Co-authored-by: Copilot <[email protected]>
@JanProvaznik

Copy link
Copy Markdown
Member

Pipeline failed again — second defect found, fixed, and validated locally

The first quoting commit (782bde4) did work (the -File path with a space now parses), but it surfaced a second, adjacent bug. The new swallowed error in PR build 1451148 (Windows_x64/x86):

dotnet-install: The current user doesn't have write access to the installation root
'D:\a\_work\1\s\src\msbuild\artifacts\bin\bootstrap\core"' to install .NET.

Note the trailing " in ...core". InstallDir is $(ArtifactsBinDir)bootstrap\core\ (ends in a backslash), so -InstallDir "...\core\" has a \" that the Windows native command-line parser treats as an escaped literal quote — the quote leaks into the value and corrupts the path.

Fix (commit 7186686)

Trim a trailing directory separator (root-preserving) before quoting:

// On Windows the native command-line parser treats a backslash before the closing quote as
// escaping it (e.g. "C:\dir\" becomes C:\dir"), so trim a trailing separator before quoting.
string installDir = TrimTrailingDirectorySeparators(InstallDir);
string scriptArgs = IsWindows
    ? $"-NoProfile -ExecutionPolicy Bypass -File \"{scriptPath}\" -Version {Version} -InstallDir \"{installDir}\""
    : $"\"{scriptPath}\" --version {Version} --install-dir \"{installDir}\"";

TrimTrailingDirectorySeparators preserves roots (C:\ stays C:\) and uses only netstandard2.0 APIs, since the inline RoslynCodeTaskFactory task compiles against netstandard2.0 (so Path.TrimEndingDirectorySeparator is not available).

Local validation

Reproduced ToolTask's exact invocation (Process with StartInfo.Arguments) against a dummy dotnet-install.ps1 placed in a path with a space, using an InstallDir ending in a backslash:

Variant Result
OLD (unquoted) Processing -File 'C:\...\with' failed ... not have a '.ps1' extension — original symptom
First fix (quoted, trailing \) INSTALLDIR=[...\bootstrap\core"] → Illegal characters in path — matches build 1451148
NEW (quoted + trim) INSTALLDIR=[...\bootstrap\core] → install OK, exit 0 ✅

Root-preservation check: C:\→C:\, /→/, D:\a\b\→D:\a\b.

Reminder: the durable fix still needs to land in dotnet/msbuild (src/MSBuild.Bootstrap.Utils/Tasks/InstallDotNetCoreTask.cs); this VMR edit will otherwise be reverted by the next forward-flow.

@JanProvaznik
JanProvaznik disabled auto-merge June 5, 2026 12:12
@JanProvaznik

Copy link
Copy Markdown
Member

Investigation: root cause is an agent-image update exposing latent unquoted-path bugs (not a product regression)

TL;DR

The VMR Windows legs began failing because the windows.vs2026.amd64 1ES pool image rolled from 2026.0522.011033 → 2026.0529.211646 (first seen on build agents ~June 5, 00:00–03:00 UTC). The new image ships pre-installed .NET SDK 10.0.300 at C:\Program Files\dotnet, which now exactly matches the VMR global.json (tools.dotnet=10.0.300). Arcade therefore reuses the global (spaced) install as DOTNET_INSTALL_DIR/DotNetRoot/DotnetTool instead of provisioning the space-free repo-local .dotnet, exposing latent unquoted-path bugs across repo build scripts.

No product source regressed — the same VMR commit passes on the old image and fails on the new one.

Evidence (internal pool, dotnet-unified-build def 1330, Windows_x64)

Build Finish (UTC) Agent image DOTNET_INSTALL_DIR Spaced-path failure
2988460 May 31 19:54 2026.0522 …\.dotnet\ no
2989057 Jun 1 13:54 2026.0522 …\.dotnet\ no (failed on IBC #6954)
2992072 Jun 4 11:31 2026.0522 …\.dotnet\ no
2992333 Jun 4 19:35 2026.0522 …\.dotnet\ no (Windows ✅)
2992502 Jun 4 23:41 2026.0522 …\.dotnet\ no
2992647 Jun 5 03:07 2026.0529 C:\Program Files\dotnet\ yes

Mechanism

eng/common/tools.ps1 (InitializeDotNetCli):

if ($useInstalledDotNetCli -and (-not $globalJsonHasRuntimes) -and ($env:DOTNET_INSTALL_DIR -eq $null)) {
    # picks dotnet from PATH -> C:\Program Files\dotnet
    $env:DOTNET_INSTALL_DIR = Split-Path $dotnetCmd.Path -Parent
}
# global install is then ADOPTED only if C:\Program Files\dotnet\sdk\<global.json version> exists

On image 0522 the global SDK didn't match → local .dotnet was provisioned (space-free, works). On image 0529 C:\Program Files\dotnet\sdk\10.0.300 exists → the spaced global path is adopted and propagated to every sub-repo build.

Ruled out: VMR / global.json change

global.json tools.dotnet has been 10.0.300 since May 13 (5bee494) — unchanged through the breakage.

Blast radius (latent unquoted-path bugs now firing)

  • msbuild bootstrap InstallDotNetCoreTask — -File/-InstallDir unquoted → fixed in this PR (782bde4, 7186686), validated locally.
  • sdk OverlaySdkOnLKG.targets:12 — <Exec Command="$(DotnetTool) --version"> unquoted → C:\Program → exit 9009 (current failure on build 1451255).
  • Likely additional repos that interpolate the dotnet/SDK path unquoted.

Distinct from #6954

That issue was the IBC drop.exe exit 1244 failure on the old image (~June 1, now fixed by disabling IBC). This spaced-path issue only surfaced once (a) the 0529 image arrived (~Jun 5) and (b) the IBC fix let builds progress to the bootstrap/overlay steps.

Resolution options

  1. Systemic (preferred): stop the VMR Windows build from reusing the spaced global SDK — e.g. pre-set DOTNET_INSTALL_DIR to a space-free repo-local path before arcade runs, so it provisions .dotnet. One change unblocks all repos.
  2. Per-repo hardening: quote dotnet/script paths in each affected repo (msbuild done; sdk next; possibly more). Legitimate defense-in-depth but whack-a-mole.
  3. Infra: ask dnceng whether the 0529 image change (pre-installing/updating SDK 10.0.300 at C:\Program Files\dotnet) was intended, since it changes build behavior for any consumer whose global.json matches.

…path

When the build SDK resolves to C:\Program Files\dotnet (arcade reusing the
machine-wide install on the new agent image), the unquoted Exec
"$(DotnetTool) --version" is parsed by cmd as C:\Program and fails with exit
code 9009. Quote the path, matching dotnet/sdk main and the other
$(DotNetTool) Exec calls which are already quoted.

Co-authored-by: Copilot <[email protected]>
@JanProvaznik

Copy link
Copy Markdown
Member

sdk hardening (commit d616390)

Quoted $(DotnetTool) in src/sdk/.../OverlaySdkOnLKG.targets so <Exec Command="&quot;$(DotnetTool)&quot; --version"> survives a spaced dotnet path (C:\Program Files\dotnet), fixing the exit code 9009 failure on build 1451255.

Note: dotnet/sdk main already quotes this (and its other $(DotNetTool) Exec calls); the release/10.0.4xx source was simply behind. Checked the sibling usages on this branch — NetAnalyzers.Package.csproj is already quoted, dn.csproj isn't present — so this was the only unquoted one in the build path. Durable fix: ensure the quoting is backported in dotnet/sdk so it flows here.

The build-server shutdown Exec in repo-projects/Directory.Build.targets ran
the dotnet path unquoted, so with a spaced build SDK (C:\Program Files\dotnet
on the new agent image) cmd parsed "C:\Program" and printed "is not
recognized". IgnoreExitCode="true" masked the failure, so the compiler server
was never shut down -- which then caused "process cannot access the file
because it is being used by another process" warnings during CleanupRepo.
Quote the path so the shutdown actually runs.

Co-authored-by: Copilot <[email protected]>
@JanProvaznik
JanProvaznik requested review from a team as code owners June 5, 2026 13:13
@JanProvaznik

Copy link
Copy Markdown
Member

Follow-up: the masked 'C:\Program' is not recognized (commit 393350c)

Good catch on that line. It is not the OverlaySdkOnLKG path (that fix worked — Windows_x86 build succeeded). It comes from a different Exec in repo-projects/Directory.Build.targets:

<Exec Command="$(DotNetTool) build-server shutdown --vbcscompiler"
      ... IgnoreExitCode="true" />

$(DotNetTool) = C:\Program Files\dotnet\dotnet.exe (spaced, unquoted) → cmd parses C:\Program → "is not recognized" → non-zero exit, but IgnoreExitCode="true" swallows it, so the build still reports 0 errors. That's the "sus but it passed."

It is not harmless though: the compiler (vbcscompiler) server is meant to be shut down here "so we can delete the obj directories," and because the shutdown silently no-ops, CleanupRepo immediately hits file locks:

Windows.Win32.winmd - The process cannot access the file because it is being used by another process.

Quoting $(DotNetTool) makes the shutdown actually run.

Notes:

  • This is the only $(DotNetTool) usage in that file; the other commands use powershell/rmdir and are unaffected.
  • Unlike the msbuild/sdk edits (mirrored source, will revert on source-flow), repo-projects/Directory.Build.targets is VMR-authored, so this fix is durable here.

@JanProvaznik

Copy link
Copy Markdown
Member

note: agent is wrong that this is not durable, backflow will fix it in upstream repo too

@lewing

lewing commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

we also need the fix in main and 10.0.1xx etc.

@lewing
lewing merged commit a835ad5 into release/10.0.4xx Jun 5, 2026
13 checks passed
@lewing
lewing deleted the darc-release/10.0.4xx-61956e16-48c7-4c04-9a0c-a02d585a7edd branch June 5, 2026 14:28
@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team June 5, 2026 14:29
JanProvaznik added a commit that referenced this pull request Jun 5, 2026
…tCoreTask

Cherry-pick of the fix from #7061 (release/10.0.4xx). When the build SDK
resolves to C:\Program Files\dotnet (arcade reusing the machine-wide install
on the new agent image), the unquoted -File/-InstallDir args broke PowerShell
parsing. Quote the script path and install dir (root-preserving trim of a
trailing separator so a quoted path ending in a backslash does not escape the
closing quote).

Co-authored-by: Copilot <[email protected]>
JanProvaznik added a commit that referenced this pull request Jun 5, 2026
…path

Cherry-pick from #7061. Unquoted "$(DotnetTool) --version" failed with exit
code 9009 when DotnetTool resolves to C:\Program Files\dotnet\dotnet.exe.
Matches dotnet/sdk main and the other already-quoted $(DotNetTool) Exec calls.

Co-authored-by: Copilot <[email protected]>
JanProvaznik added a commit that referenced this pull request Jun 5, 2026
Cherry-pick from #7061. The build-server shutdown Exec ran the dotnet path
unquoted; with a spaced build SDK (C:\Program Files\dotnet) cmd parsed
"C:\Program" and printed "is not recognized". IgnoreExitCode="true" masked the
failure, so the compiler server was never shut down, causing "file is being
used by another process" errors during CleanupRepo. Quote the path.

Co-authored-by: Copilot <[email protected]>
@JanProvaznik

Copy link
Copy Markdown
Member

@lewing additional requirement for this to hit is to have global.json specified to 10.0.300 which is not the case in 10.0.1xx (so it does not fail, but I'll harden anyway), for 10.0.3xx: #7080

@akoeplinger

Copy link
Copy Markdown
Member

@JanProvaznik thanks for the fix! please port it to main as well.

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.

4 participants