Skip to content

Commit 521ebfc

Browse files
authored
Build Avalonia.MacOS arm64.ps1
1 parent d17d4bf commit 521ebfc

File tree

1 file changed

+48
-70
lines changed

1 file changed

+48
-70
lines changed

Build/Build Avalonia.MacOS arm64.ps1

+48-70
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,48 @@
1-
# Define the core project path relative to the script's location
2-
$coreProjectPath = Join-Path -Path $PSScriptRoot -ChildPath "..\src\PicView.Core\PicView.Core.csproj"
3-
4-
# Load the .csproj file as XML
5-
[xml]$coreCsproj = Get-Content $coreProjectPath
6-
7-
# Define the package reference to replace
8-
$packageRefX64 = "Magick.NET-Q8-x64"
9-
$packageRefArm64 = "Magick.NET-Q8-arm64"
10-
11-
# Define the platform target (change this to 'x64' if building for x64)
12-
$platform = "arm64"
13-
14-
# Find the Magick.NET package reference and update it based on the platform
15-
$packageNodes = $coreCsproj.Project.ItemGroup.PackageReference | Where-Object { $_.Include -eq $packageRefX64 -or $_.Include -eq $packageRefArm64 }
16-
if ($packageNodes) {
17-
foreach ($packageNode in $packageNodes) {
18-
if ($platform -eq "arm64") {
19-
$packageNode.Include = $packageRefArm64
20-
} else {
21-
$packageNode.Include = $packageRefX64
22-
}
23-
}
24-
}
25-
26-
# Save the updated .csproj file
27-
$coreCsproj.Save($coreProjectPath)
28-
29-
# Define the project path for the actual build target
30-
$avaloniaProjectPath = Join-Path -Path $PSScriptRoot -ChildPath "..\src\PicView.Avalonia.MacOS\PicView.Avalonia.MacOS.csproj"
31-
32-
# Load the .csproj file as XML to extract the AssemblyVersion
33-
$avaloniaProjectFile = [xml](Get-Content $avaloniaProjectPath)
34-
$assemblyVersion = $avaloniaProjectFile.Project.PropertyGroup.AssemblyVersion
35-
36-
# Define the temporary output path using the system's temp folder
37-
$tempPath = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath "PicView"
38-
39-
# Define the final output path relative to the script's location
40-
$outputPath = Join-Path -Path $PSScriptRoot -ChildPath "PicView-v.$assemblyVersion-macOS-$platform"
41-
42-
# Ensure the temp directory exists
43-
if (-Not (Test-Path $tempPath)) {
44-
New-Item -Path $tempPath -ItemType Directory | Out-Null
45-
}
46-
47-
# Run dotnet publish for the Avalonia project
48-
dotnet publish $avaloniaProjectPath --runtime "osx-$platform" --self-contained true --configuration Release --output $tempPath /p:PublishReadyToRun=true
49-
50-
# Ensure the output directory exists and is empty
51-
if (Test-Path $outputPath) {
52-
Remove-Item -Path $outputPath -Recurse -Force
53-
}
54-
New-Item -Path $outputPath -ItemType Directory | Out-Null
55-
56-
# Copy the build output to the final destination
57-
Copy-Item -Path "$tempPath\*" -Destination $outputPath -Recurse -Force
58-
59-
# Remove the PDB file
60-
$pdbPath = Join-Path -Path $outputPath -ChildPath "PicView.Avalonia.pdb"
61-
if (Test-Path $pdbPath) {
62-
Remove-Item -Path $pdbPath -Force
63-
}
64-
65-
#Remove uninstended space
66-
Rename-Item -path $outputPath -NewName $outputPath.Replace(" ","")
67-
68-
# Clean up the temporary directory
69-
Start-Sleep -Seconds 2
70-
Remove-Item -Path $tempPath -Recurse -Force
1+
param (
2+
[Parameter()]
3+
[string]$Platform,
4+
5+
[Parameter()]
6+
[string]$outputPath
7+
)
8+
9+
# Define the core project path relative to the script's location
10+
$coreProjectPath = Join-Path -Path $PSScriptRoot -ChildPath "..\src\PicView.Core\PicView.Core.csproj"
11+
12+
# Load the .csproj file as XML
13+
[xml]$coreCsproj = Get-Content $coreProjectPath
14+
15+
# Define the package reference to replace
16+
$packageRefX64 = "Magick.NET-Q8-x64"
17+
$packageRefArm64 = "Magick.NET-Q8-arm64"
18+
19+
# Find the Magick.NET package reference and update it based on the platform
20+
$packageNodes = $coreCsproj.Project.ItemGroup.PackageReference | Where-Object { $_.Include -eq $packageRefX64 -or $_.Include -eq $packageRefArm64 }
21+
if ($packageNodes) {
22+
foreach ($packageNode in $packageNodes) {
23+
if ($Platform -eq "arm64") {
24+
$packageNode.Include = $packageRefArm64
25+
} else {
26+
$packageNode.Include = $packageRefX64
27+
}
28+
}
29+
}
30+
31+
# Save the updated .csproj file
32+
$coreCsproj.Save($coreProjectPath)
33+
34+
# Define the project path for the actual build target
35+
$avaloniaProjectPath = Join-Path -Path $PSScriptRoot -ChildPath "..\src\PicView.Avalonia.MacOS\PicView.Avalonia.MacOS.csproj"
36+
37+
# Run dotnet publish for the Avalonia project
38+
dotnet publish $avaloniaProjectPath --runtime "win-$Platform" --self-contained true --configuration Release --output $outputPath
39+
40+
41+
# Remove the PDB file
42+
$pdbPath = Join-Path -Path $outputPath -ChildPath "PicView.Avalonia.pdb"
43+
if (Test-Path $pdbPath) {
44+
Remove-Item -Path $pdbPath -Force
45+
}
46+
47+
#Remove uninstended space
48+
Rename-Item -path $outputPath -NewName $outputPath.Replace(" ","")

0 commit comments

Comments
 (0)