microsoft / github-actions-for-desktop-apps

This repo contains a sample WPF application to demonstrate how to create CI/CD pipelines using GitHub Actions.
MIT License
353 stars 109 forks source link

Wpf Net5 and MSIX #37

Closed easly1989 closed 3 years ago

easly1989 commented 3 years ago

Hello, I'm trying to setup a Continuous Integration action, based on the ci.yaml provided in this repository. I'm using net5 for my Wpf application, and visual studio 2019 preview. Locally I'm able to build and deploy without problems, but on the github action I receive this error

D:\a\weekly_diet_organizer\weekly_diet_organizer\DietOrganizer.Wap\DietOrganizer.Wap.wapproj : error NU1201: Project DietOrganizer is not compatible with uap10.0.16299 (UAP,Version=v10.0.16299). Project DietOrganizer supports: net5.0-windows7.0 (.NETCoreApp,Version=v5.0) [D:\a\weekly_diet_organizer\weekly_diet_organizer\DietOrganizer.sln]

this is my workflow file ` name: ci

on:
  push:
    branches: [ master ]

jobs:
  build:
    strategy:
      matrix:
        targetplatform: [x64]

    runs-on: windows-latest

    env:
      App_Packages_Directory: AppPackages
      Solution_Name: DietOrganizer.sln
      Test_Project_Path: DietOrganizer.Tests\DietOrganizer.Tests.csproj
      Wpf_Project_Path: DietOrganizer\DietOrganizer.csproj
      Wap_Project_Directory: DietOrganizer.Wap
      Wap_Project_Name: DietOrganizer.Wap.wapproj

    steps:
    - name: Checkout
      uses: actions/checkout@v2
      with:
        fetch-depth: 0

# Use Nerdbank.GitVersioning to set version variables: https://github.com/AArnott/nbgv
- name: Use Nerdbank.GitVersioning to set version variables
  uses: aarnott/nbgv@master
  with:
    setAllVars: true

# Install the .NET Core workload
- name: Install .NET Core
  uses: actions/setup-dotnet@v1
  with:
    dotnet-version: 5.0.x

# Add  MSBuild to the PATH
- name: Setup MSBuild.exe
  uses: microsoft/setup-msbuild@v1

# Update the version before build
- name: Update manifest version
  run: |
    [xml]$manifest = get-content ".\$env:Wap_Project_Directory\Package.appxmanifest"
    $manifest.Package.Identity.Version = "$env:NBGV_SimpleVersion.0"
    $manifest.save(".\$env:Wap_Project_Directory\Package.appxmanifest")

# Execute unit tests
- name: Execute unit tests
  run: dotnet test $env:Test_Project_Path

# Restore the application to populate the obj folder with RuntimeIdentifiers
- name: Restore the application
  run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration /p:RuntimeIdentifier=$env:RuntimeIdentifier
  env:
    Configuration: Debug
    RuntimeIdentifier: win-${{ matrix.targetplatform }}

# Decode the Base64 encoded Pfx
- name: Decode the Pfx
  run: |
    $pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.Base64_Encoded_Pfx }}")
    $currentDirectory = Get-Location
    $certificatePath = Join-Path -Path $currentDirectory -ChildPath $env:Wap_Project_Directory -AdditionalChildPath $env:SigningCertificate
    [IO.File]::WriteAllBytes("$certificatePath", $pfx_cert_byte)

# Build the Windows Application Packaging project
- name: Build the Windows Application Packaging Project (wapproj)
  run: msbuild $env:Solution_Path /p:Platform=$env:TargetPlatform /p:Configuration=$env:Configuration /p:UapAppxPackageBuildMode=$env:BuildMode /p:AppxBundle=$env:AppxBundle /p:PackageCertificateKeyFile=$env:SigningCertificate /p:PackageCertificatePassword=${{ secrets.Pfx_Key }}
  env:
    AppxBundle: Never
    BuildMode: SideloadOnly
    Configuration: Debug
    TargetPlatform: ${{ matrix.targetplatform }}

# Remove the .pfx
- name: Remove the .pfx
  run: Remove-Item -path $env:Wap_Project_Directory\$env:SigningCertificate

# Upload the MSIX package: https://github.com/marketplace/actions/upload-artifact
- name: Upload build artifacts
  uses: actions/upload-artifact@v1
  with:
    name: MSIX Package
    path: ${{ env.Wap_Project_Directory }}\${{ env.App_Packages_Directory }}`

Can someone help me? Is there something I can do to make it work?

Thank you in advance

LanceMcCarthy commented 3 years ago

I see 2 issues:

VS 2019 Preview

  1. GitHub Actions runners do not use VS 2019 Preview (v 16.9). the windows-latest runner uses VS 2019 16.8.

This is why it works locally for you, but not on GitHub Actions build

  1. Target Framework I see that your WPF project's TFM is set to Windows 7

<TargetFramework>net5.0-windows7.0</TargetFramework>

As far as a solution goes, I'm not exactly sure how you can use a UWP packaging project for a Windows 7 TFM, I know MSIX works downlevel via a special package manager install. Try setting the WPF project's TFM to

<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>

Maybe try multiple TFMS

<TargetFrameworks>net5.0-windows10.0.19041.0;net5.0-windows7.0</TargetFrameworks>

Check out my working builds here

WPF project settings https://github.com/LanceMcCarthy/MediaFileManager/blob/main/src/MediaFileManager/MediaFileManager.Desktop/MediaFileManager.Desktop.csproj#L4

Workflows https://github.com/LanceMcCarthy/MediaFileManager/tree/main/.github/workflows

easly1989 commented 3 years ago

In the project the targetframework it is set to

net5.0-windows

I'll try all your suggestions and let you know! Thank you

LanceMcCarthy commented 3 years ago

Oh! Maybe windows7.0 was defaulted by the SDK. Try setting it to just net5.0-windows10.0.19041.0

easly1989 commented 3 years ago

It solved my problem. Thank you, closing this