38 lines
2.1 KiB
PowerShell
38 lines
2.1 KiB
PowerShell
param(
|
|
[switch]$Test,
|
|
[switch]$Publish,
|
|
[switch]$SelfContained
|
|
)
|
|
$ErrorActionPreference = 'Stop'
|
|
$sdkCandidate = Join-Path $env:USERPROFILE '.dotnet-sdk\dotnet.exe'
|
|
$dotnet = if ($env:GATEWAY_DOTNET) { $env:GATEWAY_DOTNET } elseif (Test-Path -LiteralPath $sdkCandidate) { $sdkCandidate } else { (Get-Command dotnet -ErrorAction Stop).Source }
|
|
$previousRoot = $env:DOTNET_ROOT
|
|
$previousTelemetry = $env:DOTNET_CLI_TELEMETRY_OPTOUT
|
|
try {
|
|
$env:DOTNET_ROOT = Split-Path -Parent $dotnet
|
|
$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1'
|
|
& $dotnet build (Join-Path $PSScriptRoot 'GatewayKeepalive.sln') -c Release --nologo
|
|
if ($LASTEXITCODE -ne 0) { throw '构建失败。' }
|
|
if ($Test) {
|
|
foreach ($project in @('GatewayKeepalive.Tests', 'GatewayKeepalive.ProbeTests')) {
|
|
& $dotnet run --project (Join-Path $PSScriptRoot "tests\$project\$project.csproj") -c Release --no-build
|
|
if ($LASTEXITCODE -ne 0) { throw "$project 验证失败。" }
|
|
}
|
|
}
|
|
if ($Publish) {
|
|
$flavor = if ($SelfContained) { 'standalone' } else { 'runtime-dependent' }
|
|
$destination = Join-Path $PSScriptRoot "artifacts\publish\$flavor"
|
|
$contained = if ($SelfContained) { 'true' } else { 'false' }
|
|
& $dotnet publish (Join-Path $PSScriptRoot 'src\GatewayKeepalive.Tray\GatewayKeepalive.Tray.csproj') -c Release -r win-x64 --self-contained $contained -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:DebugType=embedded -o $destination
|
|
if ($LASTEXITCODE -ne 0) { throw '托盘版发布失败。' }
|
|
$cli = Join-Path $destination 'diagnostics'
|
|
& $dotnet publish (Join-Path $PSScriptRoot 'src\GatewayKeepalive.Cli\GatewayKeepalive.Cli.csproj') -c Release -r win-x64 --self-contained $contained -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:DebugType=embedded -o $cli
|
|
if ($LASTEXITCODE -ne 0) { throw '只读诊断工具发布失败。' }
|
|
Write-Host "发布完成:$destination"
|
|
}
|
|
}
|
|
finally {
|
|
$env:DOTNET_ROOT = $previousRoot
|
|
$env:DOTNET_CLI_TELEMETRY_OPTOUT = $previousTelemetry
|
|
}
|