diff --git a/eng/build.ps1 b/eng/build.ps1 index 1401f5c72b55ca..6f621db001220e 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. +$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,15 @@ 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 + Write-Host "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..035bd534925d22 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. +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=()