param( [string]$OutputDir = "runs/win-helper", [string]$Configuration = "Release", [ValidateSet("anycpu", "x86", "x64")] [string]$Platform = "anycpu" ) $ErrorActionPreference = "Stop" $repo = Resolve-Path -LiteralPath (Join-Path $PSScriptRoot "..") $sourceDir = Join-Path $repo "native/ISphereWinHelper" $outDirPath = Join-Path $repo $OutputDir $outExe = Join-Path $outDirPath "ISphereWinHelper.exe" if (-not (Test-Path -LiteralPath $sourceDir)) { throw "source directory not found: $sourceDir" } $candidates = @( "$env:WINDIR\Microsoft.NET\Framework64\v4.0.30319\csc.exe", "$env:WINDIR\Microsoft.NET\Framework\v4.0.30319\csc.exe" ) $csc = $candidates | Where-Object { Test-Path -LiteralPath $_ } | Select-Object -First 1 if (-not $csc) { throw ".NET Framework csc.exe v4.0.30319 not found" } New-Item -ItemType Directory -Force -Path $outDirPath | Out-Null $sources = Get-ChildItem -LiteralPath $sourceDir -Filter '*.cs' | Sort-Object Name | ForEach-Object { $_.FullName } if (-not $sources) { throw "no C# sources found in $sourceDir" } $referenceRoots = @( "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8", "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2", "$env:WINDIR\Microsoft.NET\Framework64\v4.0.30319\WPF", "$env:WINDIR\Microsoft.NET\Framework\v4.0.30319\WPF" ) function Resolve-Reference([string]$name) { foreach ($root in $referenceRoots) { $candidate = Join-Path $root $name if (Test-Path -LiteralPath $candidate) { return $candidate } } return $name } $uiaClient = Resolve-Reference "UIAutomationClient.dll" $uiaTypes = Resolve-Reference "UIAutomationTypes.dll" $windowsBase = Resolve-Reference "WindowsBase.dll" & $csc ` /nologo ` /target:exe ` /platform:$Platform ` /optimize+ ` /warn:0 ` /out:$outExe ` /reference:System.dll ` /reference:System.Core.dll ` /reference:System.Web.Extensions.dll ` /reference:System.Windows.Forms.dll ` /reference:$uiaClient ` /reference:$uiaTypes ` /reference:$windowsBase ` $sources if ($LASTEXITCODE -ne 0) { throw "win helper compilation failed with exit code $LASTEXITCODE" } $result = [ordered]@{ ok = $true configuration = $Configuration platform = $Platform csc = $csc source_dir = $sourceDir output = $outExe } $result | ConvertTo-Json -Depth 4 -Compress