251 lines
6.4 KiB
PowerShell
251 lines
6.4 KiB
PowerShell
#!/usr/bin/env pwsh
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Build script for VAV1 Player
|
|
.DESCRIPTION
|
|
This script builds the VAV1 Player application and runs tests.
|
|
It supports different build configurations and platforms.
|
|
.PARAMETER Configuration
|
|
Build configuration (Debug or Release). Default is Debug.
|
|
.PARAMETER Platform
|
|
Target platform (x64). Default is x64.
|
|
.PARAMETER SkipTests
|
|
Skip running unit tests.
|
|
.PARAMETER Clean
|
|
Clean the solution before building.
|
|
.PARAMETER Restore
|
|
Restore NuGet packages.
|
|
.PARAMETER Publish
|
|
Create a publish build.
|
|
.EXAMPLE
|
|
.\build.ps1
|
|
.\build.ps1 -Configuration Release -Platform x64
|
|
.\build.ps1 -Clean -Restore -Configuration Release
|
|
.\build.ps1 -SkipTests -Publish
|
|
#>
|
|
|
|
param(
|
|
[string]$Configuration = "Debug",
|
|
[string]$Platform = "x64",
|
|
[switch]$SkipTests,
|
|
[switch]$Clean,
|
|
[switch]$Restore,
|
|
[switch]$Publish
|
|
)
|
|
|
|
# Script configuration
|
|
$ErrorActionPreference = "Stop"
|
|
$scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
|
$solutionFile = Join-Path $scriptRoot "Vav1Player.sln"
|
|
$projectFile = Join-Path $scriptRoot "Vav1Player\Vav1Player.csproj"
|
|
$testProjectFile = Join-Path $scriptRoot "Vav1Player.Tests\Vav1Player.Tests.csproj"
|
|
|
|
# Color functions
|
|
function Write-Success { param($Message) Write-Host $Message -ForegroundColor Green }
|
|
function Write-Warning { param($Message) Write-Host $Message -ForegroundColor Yellow }
|
|
function Write-Error { param($Message) Write-Host $Message -ForegroundColor Red }
|
|
function Write-Info { param($Message) Write-Host $Message -ForegroundColor Cyan }
|
|
|
|
function Test-DotNet {
|
|
try {
|
|
$dotnetVersion = dotnet --version
|
|
Write-Info "Using .NET SDK version: $dotnetVersion"
|
|
return $true
|
|
}
|
|
catch {
|
|
Write-Error ".NET SDK not found. Please install .NET 9.0 SDK or later."
|
|
return $false
|
|
}
|
|
}
|
|
|
|
function Test-Prerequisites {
|
|
Write-Info "Checking prerequisites..."
|
|
|
|
if (-not (Test-DotNet)) {
|
|
exit 1
|
|
}
|
|
|
|
# Check for required Windows SDK components
|
|
$windowsSDKPath = "${env:ProgramFiles(x86)}\Windows Kits\10"
|
|
if (-not (Test-Path $windowsSDKPath)) {
|
|
Write-Warning "Windows 10/11 SDK not found at $windowsSDKPath"
|
|
Write-Warning "D3D12 functionality may not work properly."
|
|
}
|
|
|
|
Write-Success "Prerequisites check completed."
|
|
}
|
|
|
|
function Invoke-Clean {
|
|
Write-Info "Cleaning solution..."
|
|
|
|
if (Test-Path $solutionFile) {
|
|
dotnet clean $solutionFile --configuration $Configuration --verbosity minimal
|
|
} else {
|
|
# Clean individual projects if solution doesn't exist
|
|
dotnet clean $projectFile --configuration $Configuration --verbosity minimal
|
|
dotnet clean $testProjectFile --configuration $Configuration --verbosity minimal
|
|
}
|
|
|
|
# Remove bin and obj folders
|
|
Get-ChildItem -Path $scriptRoot -Recurse -Directory -Name "bin", "obj" |
|
|
ForEach-Object {
|
|
$path = Join-Path $scriptRoot $_
|
|
if (Test-Path $path) {
|
|
Remove-Item $path -Recurse -Force
|
|
Write-Info "Removed: $path"
|
|
}
|
|
}
|
|
|
|
Write-Success "Clean completed."
|
|
}
|
|
|
|
function Invoke-Restore {
|
|
Write-Info "Restoring NuGet packages..."
|
|
|
|
if (Test-Path $solutionFile) {
|
|
dotnet restore $solutionFile --verbosity minimal
|
|
} else {
|
|
dotnet restore $projectFile --verbosity minimal
|
|
dotnet restore $testProjectFile --verbosity minimal
|
|
}
|
|
|
|
Write-Success "Package restoration completed."
|
|
}
|
|
|
|
function Invoke-Build {
|
|
Write-Info "Building VAV1 Player ($Configuration|$Platform)..."
|
|
|
|
$buildArgs = @(
|
|
"build"
|
|
"--configuration", $Configuration
|
|
"--verbosity", "minimal"
|
|
"--no-restore"
|
|
)
|
|
|
|
if (Test-Path $solutionFile) {
|
|
$buildArgs += $solutionFile
|
|
} else {
|
|
$buildArgs += $projectFile
|
|
}
|
|
|
|
& dotnet $buildArgs
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Error "Build failed with exit code $LASTEXITCODE"
|
|
exit $LASTEXITCODE
|
|
}
|
|
|
|
Write-Success "Build completed successfully."
|
|
}
|
|
|
|
function Invoke-Tests {
|
|
if ($SkipTests) {
|
|
Write-Warning "Skipping tests as requested."
|
|
return
|
|
}
|
|
|
|
Write-Info "Running unit tests..."
|
|
|
|
$testArgs = @(
|
|
"test"
|
|
$testProjectFile
|
|
"--configuration", $Configuration
|
|
"--verbosity", "minimal"
|
|
"--no-build"
|
|
"--no-restore"
|
|
"--logger", "console;verbosity=normal"
|
|
"--settings", "test.runsettings"
|
|
)
|
|
|
|
& dotnet $testArgs
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Error "Tests failed with exit code $LASTEXITCODE"
|
|
exit $LASTEXITCODE
|
|
}
|
|
|
|
Write-Success "All tests passed."
|
|
}
|
|
|
|
function Invoke-Publish {
|
|
if (-not $Publish) {
|
|
return
|
|
}
|
|
|
|
Write-Info "Publishing VAV1 Player..."
|
|
|
|
$publishDir = Join-Path $scriptRoot "publish"
|
|
|
|
$publishArgs = @(
|
|
"publish"
|
|
$projectFile
|
|
"--configuration", $Configuration
|
|
"--output", $publishDir
|
|
"--self-contained", "false"
|
|
"--verbosity", "minimal"
|
|
"--no-restore"
|
|
"--no-build"
|
|
)
|
|
|
|
& dotnet $publishArgs
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Error "Publish failed with exit code $LASTEXITCODE"
|
|
exit $LASTEXITCODE
|
|
}
|
|
|
|
Write-Success "Publish completed. Output: $publishDir"
|
|
}
|
|
|
|
function Show-BuildInfo {
|
|
Write-Info "VAV1 Player Build Script"
|
|
Write-Info "========================"
|
|
Write-Info "Configuration: $Configuration"
|
|
Write-Info "Platform: $Platform"
|
|
Write-Info "Skip Tests: $SkipTests"
|
|
Write-Info "Clean: $Clean"
|
|
Write-Info "Restore: $Restore"
|
|
Write-Info "Publish: $Publish"
|
|
Write-Info "Working Directory: $scriptRoot"
|
|
Write-Info ""
|
|
}
|
|
|
|
# Main execution
|
|
function Main {
|
|
Show-BuildInfo
|
|
|
|
Test-Prerequisites
|
|
|
|
if ($Clean) {
|
|
Invoke-Clean
|
|
}
|
|
|
|
if ($Restore -or $Clean) {
|
|
Invoke-Restore
|
|
}
|
|
|
|
Invoke-Build
|
|
Invoke-Tests
|
|
Invoke-Publish
|
|
|
|
Write-Success "Build script completed successfully!"
|
|
|
|
if ($Publish) {
|
|
Write-Info ""
|
|
Write-Info "To run the published application:"
|
|
Write-Info "cd publish && .\Vav1Player.exe"
|
|
}
|
|
}
|
|
|
|
# Create solution file if it doesn't exist
|
|
if (-not (Test-Path $solutionFile)) {
|
|
Write-Info "Creating solution file..."
|
|
dotnet new sln --name "Vav1Player" --output $scriptRoot
|
|
dotnet sln $solutionFile add $projectFile
|
|
dotnet sln $solutionFile add $testProjectFile
|
|
Write-Success "Solution file created."
|
|
}
|
|
|
|
# Execute main function
|
|
Main |