Build Avalonia.MacOS.ps1 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. param (
  2. [Parameter()]
  3. [string]$Platform,
  4. [Parameter()]
  5. [string]$outputPath
  6. )
  7. # Define the core project path relative to the script's location
  8. $coreProjectPath = Join-Path -Path $PSScriptRoot -ChildPath "../src/PicView.Core/PicView.Core.csproj"
  9. # Load the .csproj file as XML
  10. [xml]$coreCsproj = Get-Content $coreProjectPath
  11. # Define the package reference to replace
  12. $packageRefX64 = "Magick.NET-Q8-x64"
  13. $packageRefArm64 = "Magick.NET-Q8-arm64"
  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. # Save the updated .csproj file
  26. $coreCsproj.Save($coreProjectPath)
  27. # Define the project path for the actual build target
  28. $avaloniaProjectPath = Join-Path -Path $PSScriptRoot -ChildPath "../src/PicView.Avalonia.MacOS/PicView.Avalonia.MacOS.csproj"
  29. # Run dotnet publish for the Avalonia project
  30. dotnet publish $avaloniaProjectPath `
  31. --runtime "osx-$Platform" `
  32. --self-contained true `
  33. --configuration Release `
  34. -p:PublishSingleFile=false `
  35. --output $outputPath
  36. # Remove the PDB file
  37. $pdbPath = Join-Path -Path $outputPath -ChildPath "PicView.Avalonia.pdb"
  38. if (Test-Path $pdbPath) {
  39. Remove-Item -Path $pdbPath -Force
  40. }
  41. # Remove unintended space
  42. if (Test-Path $outputPath) {
  43. $newPath = $outputPath.Replace(" ","")
  44. if ($outputPath -ne $newPath) {
  45. Rename-Item -Path $outputPath -NewName $newPath -Force
  46. }
  47. }