$ErrorActionPreference = 'Stop' $framework = Join-Path $env:WINDIR 'Microsoft.NET\Framework\v4.0.30319' $compiler = Join-Path $framework 'csc.exe' if (-not (Test-Path -LiteralPath $compiler -PathType Leaf)) { throw 'The .NET Framework C# compiler was not found.' } $outputDirectory = Join-Path $PSScriptRoot 'dist' New-Item -ItemType Directory -Path $outputDirectory -Force | Out-Null $output = Join-Path $outputDirectory 'DailyFileSync.exe' $manifest = Join-Path $PSScriptRoot 'app.manifest' $sources = 'Program.cs', 'MainForm.cs', 'StartupRegistration.cs', 'SyncSettings.cs', 'SyncEngine.cs' | ForEach-Object { Join-Path $PSScriptRoot $_ } & $compiler /nologo /target:winexe /platform:anycpu /optimize+ /codepage:65001 ` /reference:System.Windows.Forms.dll /reference:System.Drawing.dll ` "/win32manifest:$manifest" "/out:$output" @sources if ($LASTEXITCODE -ne 0) { throw "Compilation failed with exit code $LASTEXITCODE." } Write-Output $output