dotnet-desktop.yml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # This workflow uses actions that are not certified by GitHub.
  2. # They are provided by a third-party and are governed by
  3. # separate terms of service, privacy policy, and support
  4. # documentation.
  5. # This workflow will build, test, sign and package a WPF or Windows Forms desktop application
  6. # built on .NET Core.
  7. # To learn how to migrate your existing application to .NET Core,
  8. # refer to https://docs.microsoft.com/en-us/dotnet/desktop-wpf/migration/convert-project-from-net-framework
  9. #
  10. # To configure this workflow:
  11. #
  12. # 1. Configure environment variables
  13. # GitHub sets default environment variables for every workflow run.
  14. # Replace the variables relative to your project in the "env" section below.
  15. #
  16. # 2. Signing
  17. # Generate a signing certificate in the Windows Application
  18. # Packaging Project or add an existing signing certificate to the project.
  19. # Next, use PowerShell to encode the .pfx file using Base64 encoding
  20. # by running the following Powershell script to generate the output string:
  21. #
  22. # $pfx_cert = Get-Content '.\SigningCertificate.pfx' -Encoding Byte
  23. # [System.Convert]::ToBase64String($pfx_cert) | Out-File 'SigningCertificate_Encoded.txt'
  24. #
  25. # Open the output file, SigningCertificate_Encoded.txt, and copy the
  26. # string inside. Then, add the string to the repo as a GitHub secret
  27. # and name it "Base64_Encoded_Pfx."
  28. # For more information on how to configure your signing certificate for
  29. # this workflow, refer to https://github.com/microsoft/github-actions-for-desktop-apps#signing
  30. #
  31. # Finally, add the signing certificate password to the repo as a secret and name it "Pfx_Key".
  32. # See "Build the Windows Application Packaging project" below to see how the secret is used.
  33. #
  34. # For more information on GitHub Actions, refer to https://github.com/features/actions
  35. # For a complete CI/CD sample to get started with GitHub Action workflows for Desktop Applications,
  36. # refer to https://github.com/microsoft/github-actions-for-desktop-apps
  37. name: .NET Core Desktop
  38. on:
  39. push:
  40. branches: [ "Auto-Build" ]
  41. pull_request:
  42. branches: [ "Auto-Build" ]
  43. jobs:
  44. build:
  45. strategy:
  46. matrix:
  47. configuration: [Debug, Release]
  48. runs-on: windows-latest # For a list of available runner types, refer to
  49. # https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
  50. env:
  51. Solution_Name: Plain Craft Launcher 2.sln # Replace with your solution name, i.e. MyWpfApp.sln.
  52. Test_Project_Path: Plain Craft Launcher 2\Plain Craft Launcher 2.vbproj # Replace with the path to your test project, i.e. MyWpfApp.Tests\MyWpfApp.Tests.csproj.
  53. Wap_Project_Directory: Plain Craft Launcher 2 # Replace with the Wap project directory relative to the solution, i.e. MyWpfApp.Package.
  54. Wap_Project_Path: Plain Craft Launcher 2\Plain Craft Launcher 2.vbproj # Replace with the path to your Wap project, i.e. MyWpf.App.Package\MyWpfApp.Package.wapproj.
  55. steps:
  56. - name: Checkout
  57. uses: actions/checkout@v4
  58. with:
  59. fetch-depth: 0
  60. # Install the .NET Core workload
  61. - name: Install .NET Core
  62. uses: actions/setup-dotnet@v4
  63. with:
  64. dotnet-version: 5
  65. # Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
  66. - name: Setup MSBuild.exe
  67. uses: microsoft/setup-msbuild@v2
  68. # Execute all unit tests in the solution
  69. - name: Execute unit tests
  70. run: dotnet test
  71. # Restore the application to populate the obj folder with RuntimeIdentifiers
  72. - name: Restore the application
  73. run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
  74. env:
  75. Configuration: ${{ matrix.configuration }}
  76. # Decode the base 64 encoded pfx and save the Signing_Certificate
  77. - name: Decode the pfx
  78. run: |
  79. $pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.Base64_Encoded_Pfx }}")
  80. $certificatePath = Join-Path -Path $env:Wap_Project_Directory -ChildPath GitHubActionsWorkflow.pfx
  81. [IO.File]::WriteAllBytes("$certificatePath", $pfx_cert_byte)
  82. # Create the app package by building and packaging the Windows Application Packaging project
  83. - name: Create the app package
  84. run: msbuild $env:Wap_Project_Path /p:Configuration=$env:Configuration /p:UapAppxPackageBuildMode=$env:Appx_Package_Build_Mode /p:AppxBundle=$env:Appx_Bundle /p:PackageCertificateKeyFile=GitHubActionsWorkflow.pfx /p:PackageCertificatePassword=${{ secrets.Pfx_Key }}
  85. env:
  86. Appx_Bundle: Always
  87. Appx_Bundle_Platforms: x86|x64
  88. Appx_Package_Build_Mode: StoreUpload
  89. Configuration: ${{ matrix.configuration }}
  90. # Remove the pfx
  91. - name: Remove the pfx
  92. run: Remove-Item -path $env:Wap_Project_Directory\GitHubActionsWorkflow.pfx
  93. # Upload the MSIX package: https://github.com/marketplace/actions/upload-a-build-artifact
  94. - name: Upload build artifacts
  95. uses: actions/upload-artifact@v3
  96. with:
  97. name: ${{ matrix.configuration }}
  98. path: ${{ env.Wap_Project_Directory }}\obj\${{ matrix.configuration }}\Plain Craft Launcher 2.exe