#Requires -Version 5.1 $ErrorActionPreference = "Stop" $sourcePath = Join-Path $PSScriptRoot "GesisOpenCodeInstaller.cs" $outputPath = Join-Path $PSScriptRoot "GESIS-OpenCode-Installer.exe" $logoPath = Join-Path $PSScriptRoot "GESIS Logo Blau EN.jpg" $signetPath = Join-Path $PSScriptRoot "GESIS Signet Blau_transp.png" $iconPath = Join-Path $PSScriptRoot "GESIS-OpenCode-Installer.ico" $manifestPath = Join-Path $PSScriptRoot "app.manifest" $cscPath = Join-Path $env:WINDIR "Microsoft.NET\Framework64\v4.0.30319\csc.exe" if (-not (Test-Path -LiteralPath $cscPath)) { throw "Could not find the .NET Framework C# compiler at $cscPath" } if (-not (Test-Path -LiteralPath $logoPath)) { throw "Could not find logo file: $logoPath" } if (-not (Test-Path -LiteralPath $signetPath)) { throw "Could not find signet file: $signetPath" } if (-not (Test-Path -LiteralPath $manifestPath)) { throw "Could not find application manifest: $manifestPath" } Add-Type -AssemblyName System.Drawing $pngBytes = [System.IO.File]::ReadAllBytes($signetPath) $image = [System.Drawing.Image]::FromFile($signetPath) try { $width = [Math]::Min($image.Width, 255) $height = [Math]::Min($image.Height, 255) } finally { $image.Dispose() } $stream = [System.IO.File]::Open($iconPath, [System.IO.FileMode]::Create) try { $writer = New-Object System.IO.BinaryWriter($stream) $writer.Write([UInt16]0) $writer.Write([UInt16]1) $writer.Write([UInt16]1) $writer.Write([Byte]$width) $writer.Write([Byte]$height) $writer.Write([Byte]0) $writer.Write([Byte]0) $writer.Write([UInt16]1) $writer.Write([UInt16]32) $writer.Write([UInt32]$pngBytes.Length) $writer.Write([UInt32]22) $writer.Write($pngBytes) $writer.Flush() } finally { $stream.Dispose() } $compilerArgs = @( "/target:winexe", "/platform:x64", "/optimize+", "/win32icon:$iconPath", "/win32manifest:$manifestPath", "/out:$outputPath", "/resource:$logoPath,GesisLogo", "/resource:$iconPath,GesisIcon", "/reference:System.dll", "/reference:System.Core.dll", "/reference:System.Drawing.dll", "/reference:System.Web.Extensions.dll", "/reference:System.Windows.Forms.dll", $sourcePath ) & $cscPath $compilerArgs if ($LASTEXITCODE -ne 0) { throw "Compilation failed with exit code $LASTEXITCODE" } Write-Host "Built $outputPath"