39 lines
2.2 KiB
PowerShell
39 lines
2.2 KiB
PowerShell
param(
|
|
[ValidateSet('win-x64','win-arm64','linux-x64','linux-arm64','osx-x64','osx-arm64')][string]$Runtime = 'win-x64',
|
|
[switch]$FrameworkDependent
|
|
)
|
|
$ErrorActionPreference = 'Stop'
|
|
$projectRoot = Split-Path $PSScriptRoot -Parent
|
|
$outputDirectory = Join-Path $projectRoot "bin/desktop-$Runtime"
|
|
$selfContained = if ($FrameworkDependent) { 'false' } else { 'true' }
|
|
# Publish to a fresh staging folder so obsolete runtime DLLs cannot survive upgrades.
|
|
$stage = Join-Path $projectRoot ('bin/publish-desktop-' + [guid]::NewGuid().ToString('N'))
|
|
$publishOptions=@()
|
|
if ($Runtime.StartsWith('win-') -and -not $FrameworkDependent) {
|
|
$publishOptions=@('-p:PublishSingleFile=true','-p:IncludeNativeLibrariesForSelfExtract=false','-p:EnableCompressionInSingleFile=true','-p:DebugType=embedded')
|
|
}
|
|
Push-Location (Join-Path $projectRoot 'desktop')
|
|
try {
|
|
dotnet publish Ads.Desktop -c Release -r $Runtime --self-contained $selfContained -o $stage --nologo @publishOptions
|
|
if ($LASTEXITCODE -ne 0) { throw 'Desktop publish failed' }
|
|
} finally { Pop-Location }
|
|
if (Test-Path -LiteralPath $outputDirectory) {
|
|
if (Get-ChildItem -LiteralPath $outputDirectory -Recurse -File -Filter '*.env') { throw 'Private env file in release directory; refusing to replace it' }
|
|
Remove-Item -LiteralPath $outputDirectory -Recurse -Force
|
|
}
|
|
Move-Item -LiteralPath $stage -Destination $outputDirectory
|
|
$suffix = if ($Runtime.StartsWith('win-')) { '.exe' } else { '' }
|
|
foreach ($toolName in @('ads-client', 'ads-usb', 'adsctl', 'ads-agent')) {
|
|
$client = Join-Path $projectRoot ('bin/' + $toolName + $suffix)
|
|
if (Test-Path -LiteralPath $client) {
|
|
Copy-Item -LiteralPath $client -Destination (Join-Path $outputDirectory ($toolName + $suffix)) -Force
|
|
}
|
|
}
|
|
if ($Runtime.StartsWith('win-') -and (Test-Path -LiteralPath (Join-Path $projectRoot 'bin/tools/scrcpy/scrcpy.exe'))) {
|
|
$tools = Join-Path $outputDirectory 'tools/scrcpy'
|
|
New-Item -ItemType Directory -Force -Path $tools | Out-Null
|
|
Copy-Item -Path (Join-Path $projectRoot 'bin/tools/scrcpy/*') -Destination $tools -Recurse -Force
|
|
}
|
|
# Do not copy client.env or any other credential into a distributable directory.
|
|
Write-Host "Desktop published to $outputDirectory (credentials excluded)"
|