Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1649253
TEMPORARY: Overlay custom MSBuild for dotnet/msbuild#12927 investigation
ilonatommy Mar 27, 2026
2faeedc
Fix Join-Path for Windows PowerShell 5.1 compatibility
ilonatommy Mar 27, 2026
760fee9
Fix null DOTNET_INSTALL_DIR - fallback to repo-local .dotnet
ilonatommy Mar 27, 2026
957917f
Merge remote-tracking branch 'upstream/main' into msbuild-bootstrap-i…
ilonatommy Mar 27, 2026
4046c34
Retrigger CI for MSBuild bootstrap investigation 2026-03-27 15:56
ilonatommy Mar 27, 2026
d346248
Add CI monitor script for MSB3030 repro detection
ilonatommy Mar 27, 2026
76338fe
Monitor: post PR comment and disable task on MSB3030 detection
ilonatommy Mar 27, 2026
2707afb
Merge remote-tracking branch 'upstream/main' into msbuild-bootstrap-i…
ilonatommy Mar 27, 2026
552aadd
Retrigger CI for MSBuild bootstrap investigation 2026-03-27 19:59
ilonatommy Mar 27, 2026
7111d6d
Merge remote-tracking branch 'upstream/main' into msbuild-bootstrap-i…
ilonatommy Mar 30, 2026
a25e4f7
Retrigger CI for MSBuild bootstrap investigation 2026-03-30 07:43
ilonatommy Mar 30, 2026
85a12d1
Merge remote-tracking branch 'upstream/main' into msbuild-bootstrap-i…
ilonatommy Mar 30, 2026
d93994c
Retrigger CI for MSBuild bootstrap investigation 2026-03-30 09:29
ilonatommy Mar 30, 2026
fb12ae3
Merge branch 'main' of https://github.com/dotnet/aspnetcore into msbu…
ilonatommy Mar 30, 2026
1bb7f41
Merge branch 'main' into msbuild-bootstrap-investigation
ilonatommy Mar 30, 2026
96bea69
Merge remote-tracking branch 'upstream/main' into msbuild-bootstrap-i…
ilonatommy Mar 30, 2026
deceb0e
Retrigger CI for MSBuild bootstrap investigation 2026-03-30 15:30
ilonatommy Mar 30, 2026
23f7eee
Merge branch 'main' into msbuild-bootstrap-investigation
ilonatommy Mar 30, 2026
1200d71
Merge remote-tracking branch 'upstream/main' into msbuild-bootstrap-i…
ilonatommy Mar 30, 2026
c73dadc
Retrigger CI for MSBuild bootstrap investigation 2026-03-30 17:59
ilonatommy Mar 30, 2026
5d7ae0c
Merge branch 'main' into msbuild-bootstrap-investigation
ilonatommy Mar 31, 2026
74f00b0
Merge remote-tracking branch 'upstream/main' into msbuild-bootstrap-i…
ilonatommy Apr 1, 2026
e151e9c
Pin SDK to preview.1 for MSBuild bootstrap DLL compatibility
ilonatommy Apr 1, 2026
d9a947c
Merge branch 'msbuild-bootstrap-investigation' of https://github.com/…
ilonatommy Apr 1, 2026
e06b3f8
Revert upstream merges that bumped SDK to preview.3
ilonatommy Apr 1, 2026
15b737e
Update MSBuild bootstrap DLL to V2 with additional logging
ilonatommy Apr 10, 2026
a24fb6a
Merge remote-tracking branch 'origin/main' into msbuild-bootstrap-inv…
ilonatommy Apr 10, 2026
134111c
Pin SDK to preview.1 for MSBuild bootstrap DLL compatibility
ilonatommy Apr 10, 2026
dab2281
Fix ambiguous FileHandleType reference with preview.1 SDK
ilonatommy Apr 10, 2026
ca2e4df
Update MSBuild bootstrap DLL to V3 (built with preview.3 SDK)
ilonatommy Apr 10, 2026
c7bbf53
Add Microsoft.Build.Framework.dll overlay alongside Tasks DLL
ilonatommy Apr 10, 2026
c807a25
Update to V4 DLL (rebased onto current MSBuild main), remove Framewor…
ilonatommy Apr 10, 2026
7facc09
Update to V5 DLL (built from SDK preview.3 MSBuild commit 8cee1da9)
ilonatommy Apr 10, 2026
72a36e2
Update package-lock.json from main
ilonatommy Apr 10, 2026
940e9d2
Fix npm package-lock.json sync with package.json
ilonatommy Apr 10, 2026
fa7aba6
Use exact package-lock.json from main
ilonatommy Apr 10, 2026
04a7111
Restore missing submodules (MessagePack-CSharp, Directory.Build)
ilonatommy Apr 10, 2026
9866411
Sync all files with main, keep only MSBuild overlay changes
ilonatommy Apr 10, 2026
5c39f8f
Merge branch 'main' into msbuild-bootstrap-investigation
ilonatommy Jul 7, 2026
31bd3bc
Update
ilonatommy Jul 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions eng/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,35 @@ try {

$restore = $tmpRestore

# TEMPORARY: Overlay custom MSBuild bootstrap for investigating dotnet/msbuild#12927
# Overlays the FULL internally-consistent set (not just Tasks.Core) so the instrumented
# assemblies don't reference types the SDK's other MSBuild assemblies lack (which caused
# Tools.proj MSB4018 TypeLoadException 'FrameworkFileUtilities' with the single-DLL overlay).
$bootstrapDir = Join-Path (Join-Path $RepoRoot "eng") "msbuild-bootstrap"
$overlayAssemblies = @(
"Microsoft.Build.dll",
"Microsoft.Build.Framework.dll",
"Microsoft.Build.Tasks.Core.dll",
"Microsoft.Build.Utilities.Core.dll"
)
if (Test-Path (Join-Path $bootstrapDir "Microsoft.Build.Tasks.Core.dll")) {
$dotnetDir = if ($env:DOTNET_INSTALL_DIR) { $env:DOTNET_INSTALL_DIR } else { Join-Path $RepoRoot ".dotnet" }
$sdkVersion = (Get-Content (Join-Path $RepoRoot "global.json") | ConvertFrom-Json).sdk.version
$sdkDir = Join-Path (Join-Path $dotnetDir "sdk") $sdkVersion
Write-Host "=== MSBuild Bootstrap Overlay (dotnet/msbuild#12927) ==="
foreach ($asm in $overlayAssemblies) {
$src = Join-Path $bootstrapDir $asm
$targetDll = Join-Path $sdkDir $asm
if ((Test-Path $src) -and (Test-Path $targetDll)) {
Copy-Item $src $targetDll -Force
Write-Host "Overlaid: $asm -> $((Get-FileHash $targetDll -Algorithm SHA256).Hash)"
} else {
Write-Host "WARNING: skipped $asm (src or target missing)"
}
}
Write-Host "=== Overlay complete ==="
}

if ($ci) {
$global:VerbosePreference = 'Continue'
}
Expand Down
22 changes: 22 additions & 0 deletions eng/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -412,5 +412,27 @@ InitializeToolset

restore=$_tmp_restore=

# TEMPORARY: Overlay custom MSBuild bootstrap for investigating dotnet/msbuild#12927
# Overlays the FULL internally-consistent set (not just Tasks.Core) so the instrumented
# assemblies don't reference types the SDK's other MSBuild assemblies lack (which caused
# Tools.proj MSB4018 TypeLoadException 'FrameworkFileUtilities' with the single-DLL overlay).
_bootstrap_dir="$repo_root/eng/msbuild-bootstrap"
if [[ -f "$_bootstrap_dir/Microsoft.Build.Tasks.Core.dll" ]]; then
_sdk_version=$(cat "$repo_root/global.json" | sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -1)
_sdk_dir="$DOTNET_INSTALL_DIR/sdk/$_sdk_version"
echo "=== MSBuild Bootstrap Overlay (dotnet/msbuild#12927) ==="
for _asm in Microsoft.Build.dll Microsoft.Build.Framework.dll Microsoft.Build.Tasks.Core.dll Microsoft.Build.Utilities.Core.dll; do
_src="$_bootstrap_dir/$_asm"
_target_dll="$_sdk_dir/$_asm"
if [[ -f "$_src" && -f "$_target_dll" ]]; then
cp "$_src" "$_target_dll"
echo "Overlaid: $_asm -> $(sha256sum "$_target_dll" | cut -d' ' -f1)"
else
echo "WARNING: skipped $_asm (src or target missing)"
fi
done
echo "=== Overlay complete ==="
fi

MSBuild $_InitializeToolset -p:RepoRoot="$repo_root" ${msbuild_args[@]+"${msbuild_args[@]}"}
ExitWithExitCode 0
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added eng/msbuild-bootstrap/Microsoft.Build.dll
Binary file not shown.
49 changes: 49 additions & 0 deletions eng/msbuild-bootstrap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# MSBuild bootstrap overlay (dotnet/msbuild#12927 investigation)

Instrumented MSBuild assemblies used to diagnose the intermittent MSB3030
"could not copy ... file not found" copy/delete race (dotnet/msbuild#12927).

## What changed vs the previous (broken) overlay

The original overlay copied **only** `Microsoft.Build.Tasks.Core.dll`. After the SDK
was bumped (via main merge) that single instrumented DLL referenced a Framework type
the pinned SDK no longer shipped, crashing every build with:

Tools.proj(29,5): error MSB4018: System.TypeLoadException:
Could not load type 'Microsoft.Build.Framework.FrameworkFileUtilities'

This folder now ships the **full internally-consistent set** so there is no type
mismatch:

- Microsoft.Build.dll
- Microsoft.Build.Framework.dll
- Microsoft.Build.Tasks.Core.dll
- Microsoft.Build.Utilities.Core.dll

## Provenance

- Source: `dotnet/msbuild` branch `vs18.9` (18.9.2), shallow clone.
- Target framework: net10.0 (matches the pinned SDK's MSBuild TFM).
- Instrumentation: `src/Tasks/Copy.cs`, at the delete-before-overwrite site, logs

MSB-COPY-DELETE: deleting existing destination before overwrite: <path>

(MessageImportance.High, so it appears in both text logs and binlogs). This marks
every point where a Copy deletes an existing destination before overwriting it —
the exact window that races with a concurrent rebuild of that destination.
- Built with `.\build.cmd -v quiet`; assemblies taken from
`artifacts/bin/bootstrap/core/sdk/10.0.300/`.

## Wiring the overlay into the build scripts

The build scripts must copy all four assemblies (not just Tasks.Core) over the SDK.
See `overlay-hook.ps1.snippet` (eng/build.ps1) and `overlay-hook.sh.snippet`
(eng/build.sh). They loop over the four assemblies and copy each into
`.dotnet/sdk/<global.json sdk.version>/`.

## Verified locally

Overlaying onto SDK 11.0.100-preview.6.26318.108 and running a trivial overwrite
`Copy` produced no TypeLoadException and emitted:

MSB-COPY-DELETE: deleting existing destination before overwrite: <dst>
261 changes: 261 additions & 0 deletions eng/msbuild-bootstrap/monitor-msbuild-ci.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
<#
.SYNOPSIS
Monitors aspnetcore PR #66003 CI for MSB3030 errors.
Checks the "Build Analysis" check run on the PR to determine if CI is done.
If MSB3030 found: logs alert and stops. Otherwise: merges main and retriggers CI.

.NOTES
Prerequisites:
- Git configured with push access to ilonatommy/aspnetcore
- Network access to dev.azure.com and api.github.com (public, no auth needed)
#>

param(
[string]$RepoPath = "D:\aspnetcore-root\aspnetcore",
[string]$Branch = "msbuild-bootstrap-investigation",
[string]$LogFile = "D:\aspnetcore-root\msbuild-monitor.log",
[string]$PRNumber = "66003",
[string]$GHOwner = "dotnet",
[string]$GHRepo = "aspnetcore",
[string]$AzDOProjectId = "cbb18261-c48f-4abb-8651-8cdcb5474649",
[int]$CIDefinitionId = 83,
[string]$LastBuildFile = "D:\aspnetcore-root\msbuild-monitor-lastbuild.txt"
)

$ErrorActionPreference = "Stop"

function Write-Log {
param([string]$Message, [string]$Level = "INFO")
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$entry = "[$timestamp] [$Level] $Message"
Write-Host $entry
Add-Content -Path $LogFile -Value $entry
}

function Get-BuildAnalysisStatus {
# Get the "Build Analysis" check run from the PR's latest commit
$url = "https://api.github.com/repos/$GHOwner/$GHRepo/pulls/$PRNumber"
try {
$pr = Invoke-RestMethod -Uri $url -Method Get -ContentType "application/json" -Headers @{ "User-Agent" = "msbuild-monitor" }
$sha = $pr.head.sha

$checksUrl = "https://api.github.com/repos/$GHOwner/$GHRepo/commits/$sha/check-runs?per_page=100"
$checks = Invoke-RestMethod -Uri $checksUrl -Method Get -ContentType "application/json" -Headers @{ "User-Agent" = "msbuild-monitor" }

$buildAnalysis = $checks.check_runs | Where-Object { $_.name -eq "Build Analysis" } | Select-Object -First 1
return $buildAnalysis
} catch {
Write-Log "Failed to query GitHub checks API: $_" "ERROR"
return $null
}
}

function Get-LatestCIBuild {
$url = "https://dev.azure.com/dnceng-public/public/_apis/build/builds?branchName=refs/pull/$PRNumber/merge&definitions=$CIDefinitionId&queryOrder=queueTimeDescending&`$top=1&api-version=7.0"
try {
$response = Invoke-RestMethod -Uri $url -Method Get -ContentType "application/json"
if ($response.count -gt 0) { return $response.value[0] }
} catch {
Write-Log "Failed to query AzDO builds API: $_" "ERROR"
}
return $null
}

function Get-BuildTimeline {
param([int]$BuildId)
$url = "https://dev.azure.com/dnceng-public/$AzDOProjectId/_apis/build/builds/$BuildId/timeline?api-version=7.0"
try { return Invoke-RestMethod -Uri $url -Method Get -ContentType "application/json" }
catch { Write-Log "Failed to get build timeline: $_" "ERROR"; return $null }
}

function Get-BuildLogs {
param([int]$BuildId)
$url = "https://dev.azure.com/dnceng-public/$AzDOProjectId/_apis/build/builds/$BuildId/logs?api-version=7.0"
try { return Invoke-RestMethod -Uri $url -Method Get -ContentType "application/json" }
catch { Write-Log "Failed to get build logs list: $_" "ERROR"; return $null }
}

function Search-LogForMSB3030 {
param([int]$BuildId, [int]$LogId)
$url = "https://dev.azure.com/dnceng-public/$AzDOProjectId/_apis/build/builds/$BuildId/logs/$($LogId)?api-version=7.0"
try {
$content = Invoke-RestMethod -Uri $url -Method Get
$found = @()
foreach ($line in ($content -split "`n")) {
if ($line -match "MSB3030|MSB3026|Could not copy.*file|error.*copy.*file") {
$found += $line.Trim()
}
}
return $found
} catch { return @() }
}

function Merge-MainAndPush {
Push-Location $RepoPath
try {
Write-Log "Fetching upstream/main..."
git fetch upstream main 2>&1 | Out-Null

Write-Log "Checking out $Branch..."
git checkout $Branch 2>&1 | Out-Null

Write-Log "Merging upstream/main into $Branch..."
$mergeOutput = git merge upstream/main --no-edit 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Log "Merge failed: $mergeOutput" "ERROR"
git merge --abort 2>&1 | Out-Null
return $false
}

$status = git --no-pager log HEAD..upstream/main --oneline 2>&1
if ([string]::IsNullOrWhiteSpace($status)) {
Write-Log "Already up to date. Creating empty commit to retrigger CI..."
git commit --allow-empty -m "Retrigger CI for MSBuild bootstrap investigation $(Get-Date -Format 'yyyy-MM-dd HH:mm')" 2>&1 | Out-Null
} else {
Write-Log "Merged new commits from upstream/main"
}

Write-Log "Pushing to origin..."
$pushOutput = git push origin $Branch 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Log "Push failed: $pushOutput" "ERROR"
return $false
}

Write-Log "Push successful - CI will retrigger"
return $true
} finally {
Pop-Location
}
}

# === MAIN ===

Write-Log "========== MSBuild CI Monitor Run =========="

# Step 1: Check "Build Analysis" check run on the PR
Write-Log "Checking Build Analysis status for PR #$PRNumber..."
$buildAnalysis = Get-BuildAnalysisStatus

if (-not $buildAnalysis) {
Write-Log "Could not find Build Analysis check run. Will retry next cycle." "WARN"
exit 0
}

Write-Log "Build Analysis: status=$($buildAnalysis.status), conclusion=$($buildAnalysis.conclusion)"

if ($buildAnalysis.status -ne "completed") {
Write-Log "Build Analysis not completed yet. CI still running. Skipping."
exit 0
}

# Step 2: Get the latest aspnetcore-ci build to search its logs
$build = Get-LatestCIBuild
if (-not $build) {
Write-Log "No aspnetcore-ci builds found" "WARN"
Merge-MainAndPush
exit 0
}

$buildId = $build.id
$buildResult = $build.result
$buildUrl = $build._links.web.href
Write-Log "Latest aspnetcore-ci build: #$buildId, result=$buildResult"
Write-Log "URL: $buildUrl"

# Step 3: Skip if we already processed this build
if (Test-Path $LastBuildFile) {
$lastProcessed = (Get-Content $LastBuildFile -Raw).Trim()
if ($lastProcessed -eq "$buildId") {
Write-Log "Build #$buildId already processed. Skipping."
exit 0
}
}
Set-Content -Path $LastBuildFile -Value "$buildId"

# Step 4: If build succeeded, retrigger
if ($buildResult -eq "succeeded") {
Write-Log "Build #$buildId succeeded (no MSB3030). Merging main and retriggering..."
Merge-MainAndPush
exit 0
}

# Step 5: Build failed - search logs for MSB3030
Write-Log "Build #$buildId failed/partially failed. Searching logs for MSB3030..."

$foundMSB3030 = $false
$msbErrors = @()

$timeline = Get-BuildTimeline -BuildId $buildId
if ($timeline) {
$failedTasks = $timeline.records | Where-Object { $_.result -eq "failed" -and $_.log }
Write-Log "Found $($failedTasks.Count) failed tasks"
foreach ($task in $failedTasks) {
$errors = Search-LogForMSB3030 -BuildId $buildId -LogId $task.log.id
foreach ($err in $errors) {
$foundMSB3030 = $true
$msbErrors += "[$($task.name)] $err"
Write-Log " FOUND: $err" "ALERT"
}
}
}

$logsList = Get-BuildLogs -BuildId $buildId
if ($logsList) {
$searchedIds = @($failedTasks | ForEach-Object { $_.log.id })
$largeLogs = $logsList.value | Where-Object { $_.lineCount -gt 100 -and $_.id -notin $searchedIds }
Write-Log "Also searching $($largeLogs.Count) large logs..."
foreach ($log in $largeLogs) {
$errors = Search-LogForMSB3030 -BuildId $buildId -LogId $log.id
foreach ($err in $errors) {
$foundMSB3030 = $true
$msbErrors += "[log-$($log.id)] $err"
Write-Log " FOUND in log $($log.id): $err" "ALERT"
}
}
}

if ($foundMSB3030) {
Write-Log "=== MSB3030/MSB3026 ERROR DETECTED! ===" "ALERT"
Write-Log "Build: $buildUrl" "ALERT"
foreach ($err in $msbErrors) { Write-Log " $err" "ALERT" }

# Post comment on the PR
$errorList = ($msbErrors | ForEach-Object { "- ``$_``" }) -join "`n"
$comment = @"
## :rotating_light: MSB3030/MSB3026 Error Detected (Automated)

**Build:** [#$buildId]($buildUrl)

**Errors found:**
$errorList

**Action required:** Collect binlog from this build and share with MSBuild team (@OvesN on [dotnet/msbuild#12927](https://github.com/dotnet/msbuild/issues/12927)).

_This comment was posted automatically by the CI monitor script._
"@
try {
Push-Location $RepoPath
gh pr comment $PRNumber --repo "$GHOwner/$GHRepo" --body $comment
Write-Log "Posted comment on PR #$PRNumber" "ALERT"
Pop-Location
} catch {
Write-Log "Failed to post PR comment: $_" "ERROR"
}

# Disable the scheduled task so it stops running
try {
Disable-ScheduledTask -TaskName "MSBuild-CI-Monitor" -ErrorAction SilentlyContinue
Write-Log "Disabled scheduled task MSBuild-CI-Monitor"
} catch {
schtasks /Change /TN "MSBuild-CI-Monitor" /DISABLE 2>&1 | Out-Null
Write-Log "Disabled scheduled task via schtasks"
}

exit 0
} else {
Write-Log "Build failed but NOT due to MSB3030. Unrelated failure."
Write-Log "Merging main and retriggering CI..."
Merge-MainAndPush
exit 0
}
Loading