Adding build script

This commit is contained in:
Jordan Wages 2025-09-01 01:44:44 -05:00
commit 41a0417065
3 changed files with 133 additions and 2 deletions

View file

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.12.35707.178 d17.12 VisualStudioVersion = 17.12.35707.178
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdvancedCalculator", "AdvancedCalculator\AdvancedCalculator.csproj", "{690788A5-B548-4BE1-8B01-966BBE907C2D}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdvancedCalculator", "AdvancedCalculator\AdvancedCalculator.csproj", "{690788A5-B548-4BE1-8B01-966BBE907C2D}"
EndProject EndProject
@ -11,6 +11,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdvancedCalculator.Browser"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdvancedCalculator.Desktop", "AdvancedCalculator.Desktop\AdvancedCalculator.Desktop.csproj", "{E39C7683-E7DA-4730-B805-7F1F9DB624CB}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdvancedCalculator.Desktop", "AdvancedCalculator.Desktop\AdvancedCalculator.Desktop.csproj", "{E39C7683-E7DA-4730-B805-7F1F9DB624CB}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8EC462FD-D22E-90A8-E5CE-7E832BA40C5D}"
ProjectSection(SolutionItems) = preProject
build.ps1 = build.ps1
EndProjectSection
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -39,4 +44,7 @@ Global
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {223763A0-49A6-44DD-8702-1FB65776F5E9}
EndGlobalSection
EndGlobal EndGlobal

View file

@ -19,6 +19,6 @@
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.--> <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="$(AvaloniaVersion)" /> <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="$(AvaloniaVersion)" />
<PackageReference Include="CSMic.StandardLibrary" Version="2.0.0-beta-06" /> <PackageReference Include="CSMic.StandardLibrary" Version="2.0.0-beta-07" />
</ItemGroup> </ItemGroup>
</Project> </Project>

123
src/build.ps1 Normal file
View file

@ -0,0 +1,123 @@
#!/usr/bin/env pwsh
<#
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
pwsh ./build.ps1 -Targets web,android # pick targets
pwsh ./build.ps1 -Version 1.2.3 # override version (else tries git tag)
#>
param(
[string[]]$Targets = @('win','web','android'),
[string]$Configuration = 'Release',
[string]$Version = ''
)
$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'
# --- 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'
$OutDroid = Join-Path $Artifacts 'android'
New-Item -ItemType Directory -Force -Path $Artifacts,$OutWin,$OutWeb,$OutDroid | Out-Null
# --- Resolve dotnet exe once ---
$DotnetExe = (Get-Command dotnet -CommandType Application).Source
function Invoke-Dotnet {
param([Parameter(ValueFromRemainingArguments = $true)][string[]]$Args)
Write-Host ">> dotnet $($Args -join ' ')" -ForegroundColor Cyan
& $DotnetExe @Args
$code = $LASTEXITCODE
if ($code -ne 0) { throw "dotnet exited with $code" }
}
# --- Version (git tag 'vX.Y.Z' > explicit > empty) ---
if (-not $Version) {
try {
$tag = (git describe --tags --abbrev=0) 2>$null
if ($LASTEXITCODE -eq 0 -and $tag) { $Version = $tag.TrimStart('v') }
} catch { }
}
if ($Version) { Write-Host "Using Version: $Version" -ForegroundColor Yellow }
# --- Ensure SDK/workloads present ---
Invoke-Dotnet --info | Out-Null
Invoke-Dotnet workload restore
# ---------------- TARGETS ----------------
if ($Targets -contains 'win') {
# Windows desktop single-file exe (buildable from any OS)
$args = @(
'publish', $ProjDesktop,
'-c', $Configuration,
'-r', 'win-x64',
'--self-contained', 'true',
'-p:PublishSingleFile=true',
'-p:IncludeNativeLibrariesForSelfExtract=true',
'-o', $OutWin
)
if ($Version) { $args += "-p:Version=$Version" }
Invoke-Dotnet @args
}
if ($Targets -contains 'web') {
# Browser/WASM (Avalonia Web)
$args = @(
'publish', $ProjWeb,
'-c', $Configuration,
'-r', 'browser-wasm',
'--self-contained', 'true',
'-o', $OutWeb
)
if ($Version) { $args += "-p:Version=$Version" }
Invoke-Dotnet @args
Set-Content -Path (Join-Path $OutWeb 'README.txt') -Value @'
Serve these files over HTTP(S). Do not open index.html via file://
Place the folder behind any static web server.
'@
}
if ($Targets -contains 'android') {
# Android APK (unsigned unless env vars provided)
$baseArgs = @(
'publish', $ProjAndroid,
'-c', $Configuration,
'-r', 'android-arm64',
'--self-contained', 'true',
'-p:AndroidPackageFormat=apk',
'-o', $OutDroid
)
if ($Version) { $baseArgs += "-p:Version=$Version" }
# Unsigned build
Invoke-Dotnet @baseArgs
# Optional signing if env vars are set
if ($env:ANDROID_KEYSTORE -and $env:ANDROID_KEY_ALIAS -and $env:ANDROID_KEY_PASSWORD) {
$signArgs = $baseArgs + @(
'-p:AndroidKeyStore=true',
"-p:AndroidSigningKeyStore=$($env:ANDROID_KEYSTORE)",
"-p:AndroidSigningKeyAlias=$($env:ANDROID_KEY_ALIAS)",
"-p:AndroidSigningKeyPass=$($env:ANDROID_KEY_PASSWORD)",
"-p:AndroidSigningStorePass=$($env:ANDROID_KEY_PASSWORD)"
)
Invoke-Dotnet @signArgs
}
}
Write-Host "`nArtifacts -> $Artifacts" -ForegroundColor Green
Write-Host " Windows: $OutWin" -ForegroundColor Green
Write-Host " Web: $OutWeb" -ForegroundColor Green
Write-Host " Android: $OutDroid" -ForegroundColor Green