fix(build): publish from each project directory
Run dotnet publish from within Desktop/Browser/Android project folders and correct project paths. Ensures script works when invoked from ./src.
This commit is contained in:
parent
41a0417065
commit
5a5892edb7
1 changed files with 34 additions and 14 deletions
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env pwsh
|
||||
<#
|
||||
build.ps1 – cross-platform build for Avalonia (Windows exe, Web/WASM, Android APK)
|
||||
build.ps1 - cross-platform build for Avalonia (Windows exe, Web/WASM, Android APK)
|
||||
Usage:
|
||||
pwsh ./build.ps1 # build all
|
||||
pwsh ./build.ps1 -Targets win # just Windows
|
||||
|
@ -16,14 +16,16 @@ param(
|
|||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
# --- PROJECT PATHS (tweak to your repo) ---
|
||||
$ProjDesktop = 'src/AdvancedCalculator/AdvancedCalculator.csproj'
|
||||
$ProjWeb = 'src/AdvancedCalculator/AdvancedCalculator.csproj' # same csproj if multi-targeting Browser
|
||||
$ProjAndroid = 'src/AdvancedCalculator.Android/AdvancedCalculator.Android.csproj'
|
||||
# Always anchor to the folder containing this script (repo/src)
|
||||
$Root = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
Set-Location $Root
|
||||
|
||||
# --- PROJECT PATHS (relative to repo/src) ---
|
||||
$ProjDesktop = 'AdvancedCalculator.Desktop/AdvancedCalculator.Desktop.csproj'
|
||||
$ProjWeb = 'AdvancedCalculator.Browser/AdvancedCalculator.Browser.csproj'
|
||||
$ProjAndroid = 'AdvancedCalculator.Android/AdvancedCalculator.Android.csproj'
|
||||
|
||||
# --- ARTIFACTS ---
|
||||
$Root = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
Set-Location $Root
|
||||
$Artifacts = Join-Path $Root 'artifacts'
|
||||
$OutWin = Join-Path $Artifacts 'win-x64'
|
||||
$OutWeb = Join-Path $Artifacts 'web'
|
||||
|
@ -41,6 +43,23 @@ function Invoke-Dotnet {
|
|||
if ($code -ne 0) { throw "dotnet exited with $code" }
|
||||
}
|
||||
|
||||
# Run a dotnet command from within the project's directory
|
||||
function Invoke-InProjectDir {
|
||||
param(
|
||||
[Parameter(Mandatory=$true)][string]$ProjectPath,
|
||||
[Parameter(ValueFromRemainingArguments = $true)][string[]]$Args
|
||||
)
|
||||
$projDir = Split-Path -Parent $ProjectPath
|
||||
$projFile = Split-Path -Leaf $ProjectPath
|
||||
Push-Location $projDir
|
||||
try {
|
||||
Invoke-Dotnet @Args $projFile
|
||||
}
|
||||
finally {
|
||||
Pop-Location
|
||||
}
|
||||
}
|
||||
|
||||
# --- Version (git tag 'vX.Y.Z' > explicit > empty) ---
|
||||
if (-not $Version) {
|
||||
try {
|
||||
|
@ -59,7 +78,7 @@ Invoke-Dotnet workload restore
|
|||
if ($Targets -contains 'win') {
|
||||
# Windows desktop single-file exe (buildable from any OS)
|
||||
$args = @(
|
||||
'publish', $ProjDesktop,
|
||||
'publish',
|
||||
'-c', $Configuration,
|
||||
'-r', 'win-x64',
|
||||
'--self-contained', 'true',
|
||||
|
@ -68,20 +87,20 @@ if ($Targets -contains 'win') {
|
|||
'-o', $OutWin
|
||||
)
|
||||
if ($Version) { $args += "-p:Version=$Version" }
|
||||
Invoke-Dotnet @args
|
||||
Invoke-InProjectDir -ProjectPath $ProjDesktop @args
|
||||
}
|
||||
|
||||
if ($Targets -contains 'web') {
|
||||
# Browser/WASM (Avalonia Web)
|
||||
$args = @(
|
||||
'publish', $ProjWeb,
|
||||
'publish',
|
||||
'-c', $Configuration,
|
||||
'-r', 'browser-wasm',
|
||||
'--self-contained', 'true',
|
||||
'-o', $OutWeb
|
||||
)
|
||||
if ($Version) { $args += "-p:Version=$Version" }
|
||||
Invoke-Dotnet @args
|
||||
Invoke-InProjectDir -ProjectPath $ProjWeb @args
|
||||
|
||||
Set-Content -Path (Join-Path $OutWeb 'README.txt') -Value @'
|
||||
Serve these files over HTTP(S). Do not open index.html via file://
|
||||
|
@ -92,7 +111,7 @@ Place the folder behind any static web server.
|
|||
if ($Targets -contains 'android') {
|
||||
# Android APK (unsigned unless env vars provided)
|
||||
$baseArgs = @(
|
||||
'publish', $ProjAndroid,
|
||||
'publish',
|
||||
'-c', $Configuration,
|
||||
'-r', 'android-arm64',
|
||||
'--self-contained', 'true',
|
||||
|
@ -102,7 +121,7 @@ if ($Targets -contains 'android') {
|
|||
if ($Version) { $baseArgs += "-p:Version=$Version" }
|
||||
|
||||
# Unsigned build
|
||||
Invoke-Dotnet @baseArgs
|
||||
Invoke-InProjectDir -ProjectPath $ProjAndroid @baseArgs
|
||||
|
||||
# Optional signing if env vars are set
|
||||
if ($env:ANDROID_KEYSTORE -and $env:ANDROID_KEY_ALIAS -and $env:ANDROID_KEY_PASSWORD) {
|
||||
|
@ -113,7 +132,7 @@ if ($Targets -contains 'android') {
|
|||
"-p:AndroidSigningKeyPass=$($env:ANDROID_KEY_PASSWORD)",
|
||||
"-p:AndroidSigningStorePass=$($env:ANDROID_KEY_PASSWORD)"
|
||||
)
|
||||
Invoke-Dotnet @signArgs
|
||||
Invoke-InProjectDir -ProjectPath $ProjAndroid @signArgs
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,3 +140,4 @@ Write-Host "`nArtifacts -> $Artifacts" -ForegroundColor Green
|
|||
Write-Host " Windows: $OutWin" -ForegroundColor Green
|
||||
Write-Host " Web: $OutWeb" -ForegroundColor Green
|
||||
Write-Host " Android: $OutDroid" -ForegroundColor Green
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue