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
|
#!/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:
|
Usage:
|
||||||
pwsh ./build.ps1 # build all
|
pwsh ./build.ps1 # build all
|
||||||
pwsh ./build.ps1 -Targets win # just Windows
|
pwsh ./build.ps1 -Targets win # just Windows
|
||||||
|
@ -16,14 +16,16 @@ param(
|
||||||
|
|
||||||
$ErrorActionPreference = 'Stop'
|
$ErrorActionPreference = 'Stop'
|
||||||
|
|
||||||
# --- PROJECT PATHS (tweak to your repo) ---
|
# Always anchor to the folder containing this script (repo/src)
|
||||||
$ProjDesktop = 'src/AdvancedCalculator/AdvancedCalculator.csproj'
|
$Root = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
$ProjWeb = 'src/AdvancedCalculator/AdvancedCalculator.csproj' # same csproj if multi-targeting Browser
|
Set-Location $Root
|
||||||
$ProjAndroid = 'src/AdvancedCalculator.Android/AdvancedCalculator.Android.csproj'
|
|
||||||
|
# --- 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 ---
|
# --- ARTIFACTS ---
|
||||||
$Root = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
||||||
Set-Location $Root
|
|
||||||
$Artifacts = Join-Path $Root 'artifacts'
|
$Artifacts = Join-Path $Root 'artifacts'
|
||||||
$OutWin = Join-Path $Artifacts 'win-x64'
|
$OutWin = Join-Path $Artifacts 'win-x64'
|
||||||
$OutWeb = Join-Path $Artifacts 'web'
|
$OutWeb = Join-Path $Artifacts 'web'
|
||||||
|
@ -41,6 +43,23 @@ function Invoke-Dotnet {
|
||||||
if ($code -ne 0) { throw "dotnet exited with $code" }
|
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) ---
|
# --- Version (git tag 'vX.Y.Z' > explicit > empty) ---
|
||||||
if (-not $Version) {
|
if (-not $Version) {
|
||||||
try {
|
try {
|
||||||
|
@ -59,7 +78,7 @@ Invoke-Dotnet workload restore
|
||||||
if ($Targets -contains 'win') {
|
if ($Targets -contains 'win') {
|
||||||
# Windows desktop single-file exe (buildable from any OS)
|
# Windows desktop single-file exe (buildable from any OS)
|
||||||
$args = @(
|
$args = @(
|
||||||
'publish', $ProjDesktop,
|
'publish',
|
||||||
'-c', $Configuration,
|
'-c', $Configuration,
|
||||||
'-r', 'win-x64',
|
'-r', 'win-x64',
|
||||||
'--self-contained', 'true',
|
'--self-contained', 'true',
|
||||||
|
@ -68,20 +87,20 @@ if ($Targets -contains 'win') {
|
||||||
'-o', $OutWin
|
'-o', $OutWin
|
||||||
)
|
)
|
||||||
if ($Version) { $args += "-p:Version=$Version" }
|
if ($Version) { $args += "-p:Version=$Version" }
|
||||||
Invoke-Dotnet @args
|
Invoke-InProjectDir -ProjectPath $ProjDesktop @args
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($Targets -contains 'web') {
|
if ($Targets -contains 'web') {
|
||||||
# Browser/WASM (Avalonia Web)
|
# Browser/WASM (Avalonia Web)
|
||||||
$args = @(
|
$args = @(
|
||||||
'publish', $ProjWeb,
|
'publish',
|
||||||
'-c', $Configuration,
|
'-c', $Configuration,
|
||||||
'-r', 'browser-wasm',
|
'-r', 'browser-wasm',
|
||||||
'--self-contained', 'true',
|
'--self-contained', 'true',
|
||||||
'-o', $OutWeb
|
'-o', $OutWeb
|
||||||
)
|
)
|
||||||
if ($Version) { $args += "-p:Version=$Version" }
|
if ($Version) { $args += "-p:Version=$Version" }
|
||||||
Invoke-Dotnet @args
|
Invoke-InProjectDir -ProjectPath $ProjWeb @args
|
||||||
|
|
||||||
Set-Content -Path (Join-Path $OutWeb 'README.txt') -Value @'
|
Set-Content -Path (Join-Path $OutWeb 'README.txt') -Value @'
|
||||||
Serve these files over HTTP(S). Do not open index.html via file://
|
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') {
|
if ($Targets -contains 'android') {
|
||||||
# Android APK (unsigned unless env vars provided)
|
# Android APK (unsigned unless env vars provided)
|
||||||
$baseArgs = @(
|
$baseArgs = @(
|
||||||
'publish', $ProjAndroid,
|
'publish',
|
||||||
'-c', $Configuration,
|
'-c', $Configuration,
|
||||||
'-r', 'android-arm64',
|
'-r', 'android-arm64',
|
||||||
'--self-contained', 'true',
|
'--self-contained', 'true',
|
||||||
|
@ -102,7 +121,7 @@ if ($Targets -contains 'android') {
|
||||||
if ($Version) { $baseArgs += "-p:Version=$Version" }
|
if ($Version) { $baseArgs += "-p:Version=$Version" }
|
||||||
|
|
||||||
# Unsigned build
|
# Unsigned build
|
||||||
Invoke-Dotnet @baseArgs
|
Invoke-InProjectDir -ProjectPath $ProjAndroid @baseArgs
|
||||||
|
|
||||||
# Optional signing if env vars are set
|
# Optional signing if env vars are set
|
||||||
if ($env:ANDROID_KEYSTORE -and $env:ANDROID_KEY_ALIAS -and $env:ANDROID_KEY_PASSWORD) {
|
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:AndroidSigningKeyPass=$($env:ANDROID_KEY_PASSWORD)",
|
||||||
"-p:AndroidSigningStorePass=$($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 " Windows: $OutWin" -ForegroundColor Green
|
||||||
Write-Host " Web: $OutWeb" -ForegroundColor Green
|
Write-Host " Web: $OutWeb" -ForegroundColor Green
|
||||||
Write-Host " Android: $OutDroid" -ForegroundColor Green
|
Write-Host " Android: $OutDroid" -ForegroundColor Green
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue