Files
lddc/bin/build.ps1
2026-11-04 18:10:32 +01:00

36 lines
1.9 KiB
PowerShell

$ErrorActionPreference = 'Stop'
$work = Join-Path ([System.IO.Path]::GetTempPath()) ('ldcc-publish-' + [Guid]::NewGuid().ToString('N'))
$exitCode = 1
try {
if (-not (Get-Command dotnet -ErrorAction SilentlyContinue)) {
throw 'dotnet SDK non trovato. Installare un SDK compatibile con .NET 8.'
}
$publish = Join-Path $work 'publish'
$obj = (Join-Path $work 'obj') + '\'
$output = (Join-Path $work 'build') + '\'
& dotnet publish (Join-Path $PSScriptRoot 'LoopbackCapture.csproj') -c Release -o $publish "-p:BaseIntermediateOutputPath=$obj" "-p:BaseOutputPath=$output"
$exitCode = $LASTEXITCODE
if ($exitCode -eq 0) {
try {
$built = Get-Item (Join-Path $publish 'LoopbackCapture.exe')
# Guardia: un self-contained single-file pesa decine di MB. Poche centinaia di
# KB significano publish framework-dependent, che su un PC senza runtime .NET
# non parte. Meglio fallire qui che distribuire un exe che non si avvia.
if ($built.Length -lt 20MB) {
throw "publish inatteso: $($built.Length) byte. Atteso self-contained (>20 MB): controllare SelfContained/RuntimeIdentifier/PublishSingleFile in LoopbackCapture.csproj."
}
Copy-Item $built.FullName (Join-Path $PSScriptRoot 'LoopbackCapture.exe') -Force
Write-Output ("Build completata: bin\LoopbackCapture.exe ({0:N0} byte, self-contained .NET 8)." -f $built.Length)
} catch {
$exitCode = 1
Write-Error "Impossibile aggiornare bin\LoopbackCapture.exe: file in uso o accesso negato. Chiudere il bridge e ripetere la build. $($_.Exception.Message)" -ErrorAction Continue
}
}
} catch {
$exitCode = 1
Write-Error $_ -ErrorAction Continue
} finally {
if (Test-Path $work) { Remove-Item $work -Recurse -Force -ErrorAction SilentlyContinue }
}
exit $exitCode