Build Avalonia.Win32 arm64.ps1 2.6 KB

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