From 309471fc66f2e458fc00ea8dcfe3a7a39cb1f12c Mon Sep 17 00:00:00 2001 From: Dan Moseley Date: Sun, 12 Apr 2026 01:11:37 -0600 Subject: [PATCH 1/3] Set MSBUILDDEBUGPATH in eng/build.sh and eng/build.ps1 for reliable crash diagnostics The MSBUILDDEBUGPATH pipeline variable added in PR #126012 is not reaching the MSBuild process during Build product steps. Set the env var directly in the build scripts, matching the existing pattern in build-runtime.sh and tests/build.sh. Also create the directory with mkdir -p / New-Item -Force to avoid issues with MSBuild's EnsureDirectoryExists (which has no try/catch in its static constructor). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- eng/build.ps1 | 17 ++++++++++++++++- eng/build.sh | 8 ++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/eng/build.ps1 b/eng/build.ps1 index 1401f5c72b55ca..b4e2ebcfe00b0e 100644 --- a/eng/build.ps1 +++ b/eng/build.ps1 @@ -380,6 +380,14 @@ $arguments += " /clp:ForceNoAlign" # The later changes are ignored when using the cache. $env:DOTNETSDK_ALLOW_TARGETING_PACK_CACHING=0 +# Set up the directory for MSBuild debug logs, so that if MSBuild crashes (MSB4166) +# the failure.txt diagnostics are written to a known location under artifacts/log +# where they'll be captured as build artifacts. See https://github.com/dotnet/runtime/issues/92290 +$msbuildDebugLogsDir = "$PSScriptRoot/../artifacts/log/$((Get-Culture).TextInfo.ToTitleCase($configuration[0]))/MsbuildDebugLogs" +New-Item -ItemType Directory -Force -Path $msbuildDebugLogsDir | Out-Null +$env:MSBUILDDEBUGPATH = $msbuildDebugLogsDir +Write-Host "MSBUILDDEBUGPATH=$msbuildDebugLogsDir" + if ($bootstrap -eq $True) { if ($actionPassedIn) { @@ -434,7 +442,14 @@ if ($bootstrap -eq $True) { $failedBuilds = @() foreach ($config in $configuration) { - $argumentsWithConfig = $arguments + " -configuration $((Get-Culture).TextInfo.ToTitleCase($config))"; + $titleCaseConfig = $((Get-Culture).TextInfo.ToTitleCase($config)) + + # Update MSBuild debug logs directory for this configuration. + $msbuildDebugLogsDir = "$PSScriptRoot/../artifacts/log/$titleCaseConfig/MsbuildDebugLogs" + New-Item -ItemType Directory -Force -Path $msbuildDebugLogsDir | Out-Null + $env:MSBUILDDEBUGPATH = $msbuildDebugLogsDir + + $argumentsWithConfig = $arguments + " -configuration $titleCaseConfig"; foreach ($singleArch in $arch) { $argumentsWithArch = "/p:TargetArchitecture=$singleArch " + $argumentsWithConfig Invoke-Expression "& `"$PSScriptRoot/common/build.ps1`" $argumentsWithArch" diff --git a/eng/build.sh b/eng/build.sh index 590f9fa3d26eb8..4f769aa7cf9219 100755 --- a/eng/build.sh +++ b/eng/build.sh @@ -635,6 +635,14 @@ cmakeargs="${cmakeargs// /%20}" arguments+=("/p:TargetArchitecture=$arch" "/p:BuildArchitecture=$hostArch") arguments+=("/p:CMakeArgs=\"$cmakeargs\"" ${extraargs[@]+"${extraargs[@]}"}) +# Set up the directory for MSBuild debug logs, so that if MSBuild crashes (MSB4166) +# the failure.txt diagnostics are written to a known location under artifacts/log +# where they'll be captured as build artifacts. See https://github.com/dotnet/runtime/issues/92290 +MSBUILDDEBUGPATH="$scriptroot/../artifacts/log/${bootstrapConfig:-Debug}/MsbuildDebugLogs" +mkdir -p "$MSBUILDDEBUGPATH" +export MSBUILDDEBUGPATH +echo "MSBUILDDEBUGPATH=$MSBUILDDEBUGPATH" + if [[ "$bootstrap" == "1" ]]; then # Strip build actions other than -restore and -build from the arguments for the bootstrap build. bootstrapArguments=() From 979dfa1fbc83df602f5a82c0cbde2c7fdfad2d1a Mon Sep 17 00:00:00 2001 From: Dan Moseley Date: Sun, 12 Apr 2026 01:14:51 -0600 Subject: [PATCH 2/3] Remove issue URL from comments; use git history instead Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- eng/build.ps1 | 2 +- eng/build.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/build.ps1 b/eng/build.ps1 index b4e2ebcfe00b0e..b8458f9f457273 100644 --- a/eng/build.ps1 +++ b/eng/build.ps1 @@ -382,7 +382,7 @@ $env:DOTNETSDK_ALLOW_TARGETING_PACK_CACHING=0 # Set up the directory for MSBuild debug logs, so that if MSBuild crashes (MSB4166) # the failure.txt diagnostics are written to a known location under artifacts/log -# where they'll be captured as build artifacts. See https://github.com/dotnet/runtime/issues/92290 +# where they'll be captured as build artifacts. $msbuildDebugLogsDir = "$PSScriptRoot/../artifacts/log/$((Get-Culture).TextInfo.ToTitleCase($configuration[0]))/MsbuildDebugLogs" New-Item -ItemType Directory -Force -Path $msbuildDebugLogsDir | Out-Null $env:MSBUILDDEBUGPATH = $msbuildDebugLogsDir diff --git a/eng/build.sh b/eng/build.sh index 4f769aa7cf9219..035bd534925d22 100755 --- a/eng/build.sh +++ b/eng/build.sh @@ -637,7 +637,7 @@ arguments+=("/p:CMakeArgs=\"$cmakeargs\"" ${extraargs[@]+"${extraargs[@]}"}) # Set up the directory for MSBuild debug logs, so that if MSBuild crashes (MSB4166) # the failure.txt diagnostics are written to a known location under artifacts/log -# where they'll be captured as build artifacts. See https://github.com/dotnet/runtime/issues/92290 +# where they'll be captured as build artifacts. MSBUILDDEBUGPATH="$scriptroot/../artifacts/log/${bootstrapConfig:-Debug}/MsbuildDebugLogs" mkdir -p "$MSBUILDDEBUGPATH" export MSBUILDDEBUGPATH From 517582a33a07fda4cd3f7fb96a7a8ce6dd1c8421 Mon Sep 17 00:00:00 2001 From: Dan Moseley Date: Sun, 12 Apr 2026 01:16:57 -0600 Subject: [PATCH 3/3] Log MSBUILDDEBUGPATH inside per-config loop Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- eng/build.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eng/build.ps1 b/eng/build.ps1 index b8458f9f457273..6f621db001220e 100644 --- a/eng/build.ps1 +++ b/eng/build.ps1 @@ -448,8 +448,9 @@ foreach ($config in $configuration) { $msbuildDebugLogsDir = "$PSScriptRoot/../artifacts/log/$titleCaseConfig/MsbuildDebugLogs" New-Item -ItemType Directory -Force -Path $msbuildDebugLogsDir | Out-Null $env:MSBUILDDEBUGPATH = $msbuildDebugLogsDir + Write-Host "MSBUILDDEBUGPATH=$msbuildDebugLogsDir" - $argumentsWithConfig = $arguments + " -configuration $titleCaseConfig"; + $argumentsWithConfig= $arguments + " -configuration $titleCaseConfig"; foreach ($singleArch in $arch) { $argumentsWithArch = "/p:TargetArchitecture=$singleArch " + $argumentsWithConfig Invoke-Expression "& `"$PSScriptRoot/common/build.ps1`" $argumentsWithArch"