77 [switch ]$Interactive , # Opens an interactive PowerShell session
88 [switch ]$StartVsmon , # Enable the remote debugger.
99 [switch ]$NoCache , # Bypass the build cache for `eng`, and force a rebuild.
10- [switch ]$Snapshot , # Copy eng/src to temp directory to avoid file locking during Claude conflict resolution .
10+ [switch ]$Snapshot , # Copy built output to temp directory to avoid file locking during execution .
1111 [Parameter (ValueFromRemainingArguments )]
1212 [string []]$BuildArgs # Arguments passed to `Build.ps1` within the container.
1313)
@@ -48,31 +48,28 @@ if (-not $Interactive -or $BuildArgs)
4848
4949 # Change the working directory so we can use a global.json that is specific to eng.
5050 $previousLocation = Get-Location
51-
52- # Snapshot mode: copy eng/src to temp to avoid file locking during Claude conflict resolution
5351 $engSrcPath = Join-Path $PSScriptRoot $EngPath " src"
54- $snapshotDir = $null
55- if ($Snapshot )
56- {
57- $snapshotDir = Join-Path $env: TEMP " eng-snapshot-$ ( [Guid ]::NewGuid().ToString(' N' ).Substring(0 , 8 )) "
58- Write-Host " Creating snapshot of eng/src at $snapshotDir ..." - ForegroundColor Cyan
59- Copy-Item - Path $engSrcPath - Destination $snapshotDir - Recurse - Force
60- $engSrcPath = $snapshotDir
61- }
6252
6353 Set-Location $engSrcPath
6454
55+ $snapshotDir = $null
56+
6557 try
6658 {
6759 # Build caching: check if we need to rebuild
68- $projectPath = Join-Path $PSScriptRoot $EngPath " src " " Build$ProductName .csproj"
60+ $projectPath = Join-Path $engSrcPath " Build$ProductName .csproj"
6961
7062 # Find the output DLL by looking for the first DLL in bin/Debug/*/
71- $binDebugPath = Join-Path $PSScriptRoot $EngPath " src " " bin" " Debug"
63+ $binDebugPath = Join-Path $engSrcPath " bin" " Debug"
7264 $outputDll = $null
65+ $tfmDir = $null
7366 if (Test-Path $binDebugPath )
7467 {
7568 $outputDll = Get-ChildItem - Path $binDebugPath - Filter " Build$ProductName .dll" - Recurse - ErrorAction SilentlyContinue | Select-Object - First 1 | ForEach-Object { $_.FullName }
69+ if ($outputDll )
70+ {
71+ $tfmDir = Split-Path $outputDll - Parent
72+ }
7673 }
7774
7875 $needsBuild = $false
@@ -127,6 +124,10 @@ if (-not $Interactive -or $BuildArgs)
127124 if (Test-Path $binDebugPath )
128125 {
129126 $outputDll = Get-ChildItem - Path $binDebugPath - Filter " Build$ProductName .dll" - Recurse - ErrorAction SilentlyContinue | Select-Object - First 1 | ForEach-Object { $_.FullName }
127+ if ($outputDll )
128+ {
129+ $tfmDir = Split-Path $outputDll - Parent
130+ }
130131 }
131132
132133 # Update the DLL timestamp to mark the cache as valid
@@ -146,7 +147,19 @@ if (-not $Interactive -or $BuildArgs)
146147 throw " Output DLL not found. Expected path: '$outputDll '."
147148 }
148149
149- & dotnet exec $outputDll $BuildArgs
150+ # Snapshot mode: copy the TFM output directory to temp to avoid file locking during execution
151+ $execDll = $outputDll
152+ if ($Snapshot -and $tfmDir )
153+ {
154+ $snapshotDir = Join-Path $env: TEMP " eng-snapshot-$ ( [Guid ]::NewGuid().ToString(' N' ).Substring(0 , 8 )) "
155+ Write-Host " Creating snapshot of build output at $snapshotDir ..." - ForegroundColor Cyan
156+ Copy-Item - Path $tfmDir - Destination $snapshotDir - Recurse - Force
157+ $execDll = Join-Path $snapshotDir " Build$ProductName .dll"
158+ }
159+
160+ # Set the repository directory via environment variable (needed when running from snapshot)
161+ $env: ENG_REPO_DIRECTORY = $PSScriptRoot
162+ & dotnet exec $execDll $BuildArgs
150163
151164 if ($StartVsmon )
152165 {
@@ -165,6 +178,9 @@ if (-not $Interactive -or $BuildArgs)
165178 Write-Host " Cleaning up snapshot directory..." - ForegroundColor Cyan
166179 Remove-Item - Path $snapshotDir - Recurse - Force - ErrorAction SilentlyContinue
167180 }
181+
182+ # Reset environment variable
183+ $env: ENG_REPO_DIRECTORY = " "
168184 }
169185}
170186
0 commit comments