[CmdletBinding()] param( [string]$OutputDirectory = '' ) Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' $root = (Resolve-Path -LiteralPath $PSScriptRoot).Path if ([string]::IsNullOrWhiteSpace($OutputDirectory)) { $OutputDirectory = Join-Path $root 'x64\RuntimeGuard' } $output = [System.IO.Path]::GetFullPath($OutputDirectory).TrimEnd('\') + '\' $intermediateRoot = $output.TrimEnd('\') + '.int' $vswhere = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe' if (-not (Test-Path -LiteralPath $vswhere)) { throw "vswhere not found: $vswhere" } $msbuild = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild ` -find 'MSBuild\**\Bin\MSBuild.exe' | Select-Object -First 1 if ([string]::IsNullOrWhiteSpace($msbuild)) { throw 'MSBuild was not found by vswhere.' } New-Item -ItemType Directory -Force -Path $output | Out-Null New-Item -ItemType Directory -Force -Path $intermediateRoot | Out-Null function Invoke-ProjectRebuild { param( [Parameter(Mandatory)] [string]$Project, [Parameter(Mandatory)] [string]$IntermediateName ) $intermediate = (Join-Path $intermediateRoot $IntermediateName).TrimEnd('\') + '\' $arguments = @( $Project, '/m', '/t:Rebuild', '/p:Configuration=Release', '/p:Platform=x64', "/p:OutDir=$output", "/p:IntDir=$intermediate", '/v:minimal' ) & $msbuild @arguments if ($LASTEXITCODE -ne 0) { throw "MSBuild failed for $Project with exit code $LASTEXITCODE." } } $selfTestProject = Join-Path $root 'CFramework.SelfTest\CFramework.SelfTest.vcxproj' $overlayProject = Join-Path $root 'CFramework\CFramework.vcxproj' $selfTestExe = Join-Path $output 'CFramework.SelfTest.exe' $overlayExe = Join-Path $output 'CFramework.exe' Write-Host '[guard] Rebuilding offline runtime tests...' Invoke-ProjectRebuild -Project $selfTestProject -IntermediateName 'SelfTest' Write-Host '[guard] Running offline runtime tests...' & $selfTestExe if ($LASTEXITCODE -ne 0) { throw "Runtime self-test failed with exit code $LASTEXITCODE. Overlay build blocked." } Write-Host '[guard] Tests passed; rebuilding Release x64 overlay...' Invoke-ProjectRebuild -Project $overlayProject -IntermediateName 'CFramework' $selfTestHash = (Get-FileHash -LiteralPath $selfTestExe -Algorithm SHA256).Hash $overlayHash = (Get-FileHash -LiteralPath $overlayExe -Algorithm SHA256).Hash Write-Host "[guard] PASS" Write-Host "[guard] SelfTest: $selfTestExe" Write-Host "[guard] SelfTest SHA256: $selfTestHash" Write-Host "[guard] Overlay: $overlayExe" Write-Host "[guard] Overlay SHA256: $overlayHash"