104 lines
2.8 KiB
PowerShell
104 lines
2.8 KiB
PowerShell
|
|
[CmdletBinding()]
|
|||
|
|
param(
|
|||
|
|
[ValidateSet('Debug', 'Release')]
|
|||
|
|
[string]$Configuration = 'Release',
|
|||
|
|
|
|||
|
|
[string]$Runtime = 'win-x64',
|
|||
|
|
|
|||
|
|
[bool]$SelfContained = $true,
|
|||
|
|
|
|||
|
|
[bool]$SingleFile = $false,
|
|||
|
|
|
|||
|
|
[switch]$NoBuild,
|
|||
|
|
[switch]$Test,
|
|||
|
|
[switch]$Seed,
|
|||
|
|
[switch]$CleanSeed,
|
|||
|
|
[switch]$NoLaunch,
|
|||
|
|
[switch]$Wait,
|
|||
|
|
[switch]$Clean
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
$ErrorActionPreference = 'Stop'
|
|||
|
|
$root = $PSScriptRoot
|
|||
|
|
Set-Location $root
|
|||
|
|
|
|||
|
|
$sln = Join-Path $root 'SSPCTester.sln'
|
|||
|
|
$uiProj = Join-Path $root 'SSPCTester.UI\SSPCTester.UI.csproj'
|
|||
|
|
$testProj = Join-Path $root 'SSPCTester.Tests\SSPCTester.Tests.csproj'
|
|||
|
|
$seedProj = Join-Path $root 'SSPCTester.Seed\SSPCTester.Seed.csproj'
|
|||
|
|
$projectsRoot = Join-Path $env:LOCALAPPDATA 'SSPCTester\Projects'
|
|||
|
|
|
|||
|
|
$publishDir = Join-Path $root "publish\$Runtime"
|
|||
|
|
$exe = Join-Path $publishDir 'SSPCTester.UI.exe'
|
|||
|
|
|
|||
|
|
function Write-Step([string]$msg) {
|
|||
|
|
Write-Host ""
|
|||
|
|
Write-Host "==> $msg" -ForegroundColor Cyan
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ($Clean -and (Test-Path $publishDir)) {
|
|||
|
|
Write-Step "Clean publish dir: $publishDir"
|
|||
|
|
Remove-Item -Path $publishDir -Recurse -Force
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (-not $NoBuild) {
|
|||
|
|
Write-Step "Publish ($Configuration, $Runtime, SelfContained=$SelfContained, SingleFile=$SingleFile)"
|
|||
|
|
|
|||
|
|
$publishArgs = @(
|
|||
|
|
'publish', $uiProj,
|
|||
|
|
'-c', $Configuration,
|
|||
|
|
'-r', $Runtime,
|
|||
|
|
"-p:SelfContained=$($SelfContained.ToString().ToLower())",
|
|||
|
|
"-p:PublishSingleFile=$($SingleFile.ToString().ToLower())",
|
|||
|
|
'-p:IncludeNativeLibrariesForSelfExtract=true',
|
|||
|
|
'-p:DebugType=embedded',
|
|||
|
|
'-o', $publishDir,
|
|||
|
|
'--nologo'
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
& dotnet @publishArgs
|
|||
|
|
if ($LASTEXITCODE -ne 0) { throw "Publish failed (exit $LASTEXITCODE)." }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ($Test) {
|
|||
|
|
Write-Step "Test"
|
|||
|
|
& dotnet test $testProj -c $Configuration --no-build --nologo
|
|||
|
|
if ($LASTEXITCODE -ne 0) { throw "Tests failed (exit $LASTEXITCODE)." }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ($Seed) {
|
|||
|
|
if ($CleanSeed) {
|
|||
|
|
Write-Step "Clean ProjectsRoot: $projectsRoot"
|
|||
|
|
if (Test-Path $projectsRoot) {
|
|||
|
|
Remove-Item -Path "$projectsRoot\*" -Recurse -Force
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Write-Step "Seed virtual projects"
|
|||
|
|
& dotnet run --project $seedProj -c $Configuration -- $projectsRoot
|
|||
|
|
if ($LASTEXITCODE -ne 0) { throw "Seed failed (exit $LASTEXITCODE)." }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ($NoLaunch) { return }
|
|||
|
|
|
|||
|
|
if (-not (Test-Path $exe)) {
|
|||
|
|
throw "Executable not found: $exe"
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Write-Step "Launch $exe"
|
|||
|
|
|
|||
|
|
$proc = Start-Process -FilePath $exe -WorkingDirectory $publishDir -PassThru
|
|||
|
|
|
|||
|
|
Start-Sleep -Seconds 2
|
|||
|
|
|
|||
|
|
if ($proc.HasExited) {
|
|||
|
|
throw "Program started but exited immediately. ExitCode=$($proc.ExitCode)."
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Write-Host "Started PID=$($proc.Id)" -ForegroundColor Green
|
|||
|
|
|
|||
|
|
if ($Wait) {
|
|||
|
|
Write-Host "Waiting for process to exit (Ctrl+C to abort)..."
|
|||
|
|
$proc.WaitForExit()
|
|||
|
|
Write-Host "Exited with code $($proc.ExitCode)" -ForegroundColor Yellow
|
|||
|
|
}
|