<# .SYNOPSIS Publishes the self-contained single-file Agent executable and its watchdog per platform, zips each, and builds the MSI (win-x64) when the WiX project is present. Windows RIDs publish the net10.0-windows flavor (WMI, ConPTY, DPAPI, service); everything else publishes the portable net10.0 flavor (file config, systemd/launchd, no remote shell). .EXAMPLE ./scripts/Package-Agent.ps1 ./scripts/Package-Agent.ps1 -Version 1.4.0 -SkipMsi ./scripts/Package-Agent.ps1 -Runtimes win-x64,linux-x64,linux-arm64,osx-x64,osx-arm64 #> [CmdletBinding()] param( [string]$Version, [string[]]$Runtimes = @('win-x64'), [switch]$SkipMsi, # Package without the Remote View screen host (src/ScreenHost, Rust). [switch]$SkipScreenHost ) $ErrorActionPreference = 'Stop' $repoRoot = Split-Path -Parent $PSScriptRoot $Version = & (Join-Path $PSScriptRoot 'Get-Version.ps1') -Version $Version # The MSI ProductVersion takes four fields: a release X.Y.Z is X.Y.Z.0. $fileVersion = & (Join-Path $PSScriptRoot 'Get-Version.ps1') -Version $Version -Format FileVersion $short = & (Join-Path $PSScriptRoot 'Get-Version.ps1') -Version $Version -Format Short $artifacts = Join-Path $repoRoot 'artifacts' Write-Host "Packaging Agent $Version for: $($Runtimes -join ', ')" # Native AOT (the banner) links with MSVC: Visual Studio (Build Tools) with the C++ # tools for the target architecture, found through vswhere. The ILCompiler's # vcvarsall call runs vswhere.exe from PATH on newer Visual Studio versions, so its # folder goes on PATH for this script. function Test-NativeAotToolchain([string]$rid) { $installer = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer' $vswhere = Join-Path $installer 'vswhere.exe' if (-not (Test-Path $vswhere)) { return $false } if (($env:PATH -split ';') -notcontains $installer) { $env:PATH = "$installer;$env:PATH" } $component = if ($rid -like '*-arm64') { 'Microsoft.VisualStudio.Component.VC.Tools.ARM64' } else { 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64' } return [bool](& $vswhere -latest -prerelease -products * -requires $component -property installationPath) } # Gallery modules bundled next to the binary (PSResourceGet, Archive, ThreadJob). $modulesStage = & (Join-Path $PSScriptRoot 'Get-AgentModules.ps1') | Select-Object -Last 1 # The Remote View screen host (ExecuteR-Screen.exe) for win-x64: beside the agent in # the zip (also what Windows PE installs) and in the MSI. Skipped while src/ScreenHost # is absent or cargo is missing; other platforms do not package it yet. $screenHost = $null if (-not $SkipScreenHost -and ($Runtimes -contains 'win-x64')) { $screenHost = & (Join-Path $PSScriptRoot 'Build-ScreenHost.ps1') -Version $Version | Select-Object -Last 1 } foreach ($rid in $Runtimes) { $ridPublishDir = Join-Path $artifacts "agent/$Version/$rid" if (Test-Path $ridPublishDir) { Remove-Item $ridPublishDir -Recurse -Force } $framework = if ($rid -like 'win-*') { 'net10.0-windows' } else { 'net10.0' } dotnet publish (Join-Path $repoRoot 'src/Agent/Agent.csproj') ` -c Release ` -f $framework ` -r $rid ` --self-contained true ` -p:PublishSingleFile=true ` -p:IncludeNativeLibrariesForSelfExtract=true ` -p:EnableCompressionInSingleFile=true ` -p:DebugType=None ` "-p:UnifiedVersion=$Version" ` "-p:GitCommitShort=$short" ` -o $ridPublishDir if ($LASTEXITCODE -ne 0) { throw "Agent publish for $rid failed ($LASTEXITCODE)." } # Shipping bundles carry no debug symbols. Get-ChildItem $ridPublishDir -Filter '*.pdb' -Recurse | Remove-Item -Force # A lowercase binary name on unix; Windows keeps ExecuteR-Agent.exe, which # the MSI harvest expects and which names the rolling log after itself. if ($rid -notlike 'win-*') { Rename-Item (Join-Path $ridPublishDir 'ExecuteR-Agent') 'executer-agent' } # The watchdog (keeps the agent running, applies upgrades) travels in every # package beside the agent: one small trimmed single-file binary per RID. $watchdogPublishDir = Join-Path $artifacts "watchdog/$Version/$rid" if (Test-Path $watchdogPublishDir) { Remove-Item $watchdogPublishDir -Recurse -Force } dotnet publish (Join-Path $repoRoot 'src/Agent.Watchdog/Agent.Watchdog.csproj') ` -c Release ` -r $rid ` -p:DebugType=None ` "-p:UnifiedVersion=$Version" ` "-p:GitCommitShort=$short" ` -o $watchdogPublishDir if ($LASTEXITCODE -ne 0) { throw "Watchdog publish for $rid failed ($LASTEXITCODE)." } if ($rid -like 'win-*') { Copy-Item (Join-Path $watchdogPublishDir 'ExecuteR-Watchdog.exe') $ridPublishDir } else { Copy-Item (Join-Path $watchdogPublishDir 'ExecuteR-Watchdog') (Join-Path $ridPublishDir 'executer-watchdog') } if ($rid -eq 'win-x64' -and $screenHost) { Copy-Item $screenHost (Join-Path $ridPublishDir 'ExecuteR-Screen.exe') } # The Being Viewed banner (Remote View, policy RemoteViewBanner): Windows only, one # Native AOT binary (plain Win32, about 1.6 MB) beside the agent (zip and MSI). The # Windows PE install removes it again (no one signs in there). if ($rid -like 'win-*') { $bannerPublishDir = Join-Path $artifacts "banner/$Version/$rid" if (Test-Path $bannerPublishDir) { Remove-Item $bannerPublishDir -Recurse -Force } $bannerArgs = @() if (Test-NativeAotToolchain $rid) { Write-Host "Banner ($rid): Native AOT" } else { # No MSVC linker for this architecture (Visual Studio Build Tools, "Desktop # development with C++", plus the ARM64 tools for win-arm64): the same code as # a trimmed, self-contained single file instead (about 10x larger, slower start). Write-Warning "Banner ($rid): no MSVC tools for Native AOT; publishing a trimmed single file instead." $bannerArgs = @('-p:PublishAot=false', '-p:SelfContained=true', '-p:PublishSingleFile=true', '-p:PublishTrimmed=true', '-p:EnableCompressionInSingleFile=true') } dotnet publish (Join-Path $repoRoot 'src/Agent.Banner/Agent.Banner.csproj') ` -c Release ` -r $rid ` -p:DebugType=None ` "-p:UnifiedVersion=$Version" ` "-p:GitCommitShort=$short" ` @bannerArgs ` -o $bannerPublishDir if ($LASTEXITCODE -ne 0) { throw "Banner publish for $rid failed ($LASTEXITCODE)." } Copy-Item (Join-Path $bannerPublishDir 'ExecuteR-Banner.exe') $ridPublishDir } Copy-Item $modulesStage (Join-Path $ridPublishDir 'Modules') -Recurse # Licence terms and third-party notices travel with every package. Copy-Item (Join-Path $repoRoot 'LICENSE'), (Join-Path $repoRoot 'THIRD-PARTY-NOTICES.md') $ridPublishDir $zipPath = Join-Path $artifacts "ExecuteR-Agent-$Version-$rid.zip" if (Test-Path $zipPath) { Remove-Item $zipPath -Force } Compress-Archive -Path (Join-Path $ridPublishDir '*') -DestinationPath $zipPath Write-Host "Created $zipPath" } $publishDir = Join-Path $artifacts "agent/$Version/win-x64" $wixProject = Join-Path $repoRoot 'src/Installer/Agent.Installer.wixproj' if (-not $SkipMsi -and (Test-Path $wixProject) -and (Test-Path $publishDir)) { # ProductVersion is the four-field version (1.4.0.0, 1.4.0.7). Windows # Installer compares only three fields, so the MSI removes every installed # version and its FindNewerRelease custom action refuses a newer one. Write-Host "MSI ProductVersion: $fileVersion" dotnet build $wixProject -c Release --nologo ` "-p:UnifiedVersion=$Version" ` "-p:MsiProductVersion=$fileVersion" ` "-p:AgentPublishDir=$publishDir" if ($LASTEXITCODE -ne 0) { throw "MSI build failed ($LASTEXITCODE)." } $msi = Get-ChildItem (Join-Path $repoRoot 'src/Installer/bin/Release') -Filter '*.msi' -Recurse | Sort-Object LastWriteTimeUtc -Descending | Select-Object -First 1 if ($msi) { $msiTarget = Join-Path $artifacts "ExecuteR-Agent-$Version.msi" Copy-Item $msi.FullName $msiTarget -Force Write-Host "Created $msiTarget" } } # Checksums for release attachment. $checksums = Join-Path $artifacts "ExecuteR-Agent-$Version-checksums.txt" # This version's files only: 1.4.0's pattern must not take 1.4.0.7's. $ownFile = '^ExecuteR-Agent-' + [regex]::Escape($Version) + '(-.+\.zip|\.msi)$' Get-ChildItem $artifacts -File | Where-Object { $_.Name -match $ownFile } | ForEach-Object { "{0} {1}" -f (Get-FileHash $_.FullName -Algorithm SHA256).Hash.ToLowerInvariant(), $_.Name } | Set-Content $checksums -Encoding utf8NoBOM Write-Host "Created $checksums"