param( [string]$OutputDir = "runs/native-helper", [string]$Configuration = "Release", [ValidateSet("x86", "anycpu")] [string]$Platform = "x86" ) $ErrorActionPreference = "Stop" $repo = Resolve-Path -LiteralPath (Join-Path $PSScriptRoot "..") $source = Join-Path $repo "native/ISphereOfflineLabHelper/Program.cs" $outDirPath = Join-Path $repo $OutputDir $outExe = Join-Path $outDirPath "ISphereOfflineLabHelper.exe" $stubSource = Join-Path $outDirPath "IMPP.Resource.stub.cs" $stubResources = Join-Path $outDirPath "IMPP.Resource.Properties.Resources.resources" $stubDll = Join-Path $outDirPath "IMPP.Resource.dll" if (-not (Test-Path -LiteralPath $source)) { throw "source not found: $source" } $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 Add-Type -AssemblyName System.Drawing $resourceNameFile = Join-Path $repo "native/ISphereOfflineLabHelper/resource-names.txt" $resourceNames = New-Object System.Collections.Generic.SortedSet[string]([System.StringComparer]::Ordinal) if (Test-Path -LiteralPath $resourceNameFile) { Get-Content -LiteralPath $resourceNameFile | ForEach-Object { $name = $_.Trim() if ($name) { [void]$resourceNames.Add($name) } } } foreach ($name in @( "about_logo", "ipload_2", "login_backimg", "sys_Logo_BackImg", "sys_Logo_16", "sys_logo_50", "sys_logo_all", "sys_logo_offline16", "sys_small", "toolstript_search_background", "window_default_head" )) { [void]$resourceNames.Add($name) } $resourceWriter = New-Object System.Resources.ResourceWriter($stubResources) try { $bitmap = New-Object System.Drawing.Bitmap 1, 1 $bitmap.SetPixel(0, 0, [System.Drawing.Color]::Transparent) foreach ($name in $resourceNames) { $resourceWriter.AddResource($name, $bitmap) } } finally { $resourceWriter.Generate() $resourceWriter.Close() } @" namespace IMPP.Resource.Properties { internal static class Resources { } } "@ | Set-Content -LiteralPath $stubSource -Encoding UTF8 & $csc ` /nologo ` /target:library ` /platform:$Platform ` /optimize+ ` /out:$stubDll ` /reference:System.dll ` /reference:System.Drawing.dll ` /resource:$stubResources,IMPP.Resource.Properties.Resources.resources ` $stubSource if ($LASTEXITCODE -ne 0) { throw "IMPP.Resource stub compilation failed with exit code $LASTEXITCODE" } & $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:System.Drawing.dll ` $source if ($LASTEXITCODE -ne 0) { throw "native helper compilation failed with exit code $LASTEXITCODE" } $result = [ordered]@{ ok = $true configuration = $Configuration platform = $Platform csc = $csc source = $source output = $outExe resource_stub = $stubDll } $result | ConvertTo-Json -Depth 4 -Compress