$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
$out = Join-Path $root 'bin'
New-Item -ItemType Directory -Path $out -Force | Out-Null
$compiler = "$env:WINDIR\Microsoft.NET\Framework64\v4.0.30319\csc.exe"
if (-not (Test-Path -LiteralPath $compiler)) { $compiler = "$env:WINDIR\Microsoft.NET\Framework\v4.0.30319\csc.exe" }
if (-not (Test-Path -LiteralPath $compiler)) { throw 'Compilador .NET Framework nao encontrado.' }
& $compiler /nologo /target:exe /optimize+ /platform:anycpu /out:"$out\Agente-TI-Extrema-Windows.exe" /reference:System.Management.dll /reference:System.Net.Http.dll /reference:System.Web.Extensions.dll /reference:System.Security.dll "$root\src\Program.cs"
if ($LASTEXITCODE -ne 0) { throw 'Falha na compilacao.' }
Write-Host "Compilado: $out\Agente-TI-Extrema-Windows.exe"
