Files
2026-10-07 15:31:23 +00:00

27 lines
2.1 KiB
PowerShell

param([switch]$Tests)
$ErrorActionPreference = 'Stop'
$projectDirectory = $PSScriptRoot
$frameworkDirectory = Join-Path $env:WINDIR 'Microsoft.NET\Framework64\v4.0.30319'
$compilerPath = Join-Path $frameworkDirectory 'csc.exe'
if (-not (Test-Path -LiteralPath $compilerPath)) { throw 'The .NET Framework C# compiler is required. On Windows, install .NET Framework 4.8 developer tools or build UniClik.csproj with a .NET SDK.' }
$outputDirectory = Join-Path $projectDirectory 'dist'
New-Item -ItemType Directory -Path $outputDirectory -Force | Out-Null
$sources = @(Get-ChildItem -LiteralPath (Join-Path $projectDirectory 'src') -Filter '*.cs' | ForEach-Object FullName)
$references = @('System.dll','System.Core.dll','System.Drawing.dll','System.Windows.Forms.dll','System.Web.Extensions.dll')
$arguments = @('/nologo','/optimize+','/warn:4','/platform:x64','/codepage:65001')
$arguments += $references | ForEach-Object { '/reference:' + (Join-Path $frameworkDirectory $_) }
$arguments += @('UIAutomationClient.dll','UIAutomationTypes.dll','WindowsBase.dll') | ForEach-Object { '/reference:' + (Join-Path (Join-Path $frameworkDirectory 'WPF') $_) }
$arguments += '/resource:' + (Join-Path $projectDirectory 'assets\uniclik-icon.png') + ',UniClik.IconPng'
$arguments += '/win32icon:' + (Join-Path $projectDirectory 'assets\uniclik-icon.ico')
$arguments += '/win32manifest:' + (Join-Path $projectDirectory 'app.manifest')
$executable = Join-Path $outputDirectory 'UniClik.exe'
if (Get-Process UniClik -ErrorAction SilentlyContinue) { $executable = Join-Path $outputDirectory 'UniClik.next.exe' }
& $compilerPath @arguments '/target:winexe' '/main:UniClik.Program' ('/out:' + $executable) @sources
if ($LASTEXITCODE -ne 0) { throw 'UniClik compilation failed.' }
if ($Tests) {
$testSources = @(Get-ChildItem -LiteralPath (Join-Path $projectDirectory 'tests') -Filter '*.cs' | ForEach-Object FullName)
& $compilerPath @arguments '/target:exe' '/main:UniClik.Tests.Runner' ('/out:' + (Join-Path $outputDirectory 'UniClik.Tests.exe')) @sources @testSources
if ($LASTEXITCODE -ne 0) { throw 'UniClik test compilation failed.' }
}
Write-Output "Built $executable"