param( [string[]]$Targets = @('win-x64','linux-x64','linux-arm64','osx-x64','osx-arm64'), [ValidateSet('Aot','Trimmed','Pack')][string]$Mode = 'Pack' ) $ErrorActionPreference = 'Stop' $root = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path $localDotnet = Join-Path $root '.dotnet\dotnet.exe' $dotnet = if (Test-Path -LiteralPath $localDotnet) { $localDotnet } else { (Get-Command dotnet -ErrorAction Stop).Source } if (Test-Path -LiteralPath $localDotnet) { $env:DOTNET_CLI_HOME = Join-Path $root '.dotnet' $env:NUGET_PACKAGES = Join-Path $env:DOTNET_CLI_HOME 'packages' } $allowed = @('win-x64','linux-x64','linux-arm64','osx-x64','osx-arm64') $platform = if ($IsWindows -or $env:OS -eq 'Windows_NT') { 'win' } elseif ($IsMacOS) { 'osx' } else { 'linux' } $payload = if ($env:LANUPS_INSTALLER_PAYLOAD) { $env:LANUPS_INSTALLER_PAYLOAD } else { Join-Path $root 'artifacts\installer-payload-optimized' } foreach ($rid in $Targets) { if ($rid -notin $allowed) { throw "Unsupported target: $rid" } if ($Mode -eq 'Pack') { continue } if ($Mode -eq 'Aot' -and !$rid.StartsWith("$platform-")) { throw "Native AOT for $rid must be built on a $($rid.Split('-')[0]) host" } $publish = if ($Mode -eq 'Aot') { @('-p:PublishAot=true','-p:OptimizationPreference=Size') } else { @('-p:PublishTrimmed=true') } foreach ($kind in @('Agent','Desktop')) { $project = Join-Path $root "desktop\src\LanUps.$kind\LanUps.$kind.csproj" $output = Join-Path $payload "$rid\$kind" $temporary = "$output.$([guid]::NewGuid()).publish" & $dotnet publish $project -c Release -r $rid --self-contained true @publish --disable-build-servers -o $temporary -v minimal if ($LASTEXITCODE) { exit $LASTEXITCODE } if (Test-Path -LiteralPath $output) { $backup = "$output.$([guid]::NewGuid()).previous" Move-Item -LiteralPath $output -Destination $backup try { Move-Item -LiteralPath $temporary -Destination $output } catch { Move-Item -LiteralPath $backup -Destination $output; throw } $resolvedBackup = (Resolve-Path -LiteralPath $backup).Path $resolvedParent = (Resolve-Path -LiteralPath (Split-Path -Parent $output)).Path if ((Split-Path -Parent $resolvedBackup) -eq $resolvedParent -and (Split-Path -Leaf $resolvedBackup) -like "$kind.*.previous") { Remove-Item -LiteralPath $resolvedBackup -Recurse -Force } } else { Move-Item -LiteralPath $temporary -Destination $output } } } & python (Join-Path $PSScriptRoot 'native_packages.py') @Targets exit $LASTEXITCODE