I'm trying to configure a GitHub action that builds my multi-target Xamarin.Forms plugin and pushes the package to GitHub and NuGet. Pushing the package to GitHub and NuGet shouldn't be much of a problem anymore. I'm having trouble with building my multi-targeted nuget package on the GitHub CI.
First I had the following GitHub action:
name: .NET Core
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1.5.0
with:
dotnet-version: 3.1.301
# Authenticates packages to push to GPR
source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
env:
NUGET_AUTH_TOKEN: '%NUGET_AUTH_TOKEN%'
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --no-restore --verbosity normal
- name: Pack
run: dotnet pack --no-build --configuration Release MintPlayer.MVVM/MintPlayer.MVVM.csproj --output .
- name: PushNuget
run: dotnet nuget push *.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.PUBLISH_TO_NUGET_ORG }} --skip-duplicate
- name: PushGithub
#run: dotnet nuget push *.nupkg --source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json --api-key ${{ github.token }} --no-symbols --skip-duplicate
run: dotnet nuget push *.nupkg --no-symbols --skip-duplicate
env:
NUGET_AUTH_TOKEN: ${{ github.token }}
and also the following nuget.config in my solution root, to let the action know about the nuget source to download the required NuGet packages:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
When pushing this configuration to my GitHub repository, I'm getting the following errors at the Build stage:
/Users/runner/work/MintPlayer.MVVM/MintPlayer.MVVM/Demo/MintPlayer.MVVM.Demo/MintPlayer.MVVM.Demo.UWP/MintPlayer.MVVM.Demo.UWP.csproj(175,3): error MSB4019: The imported project "/Users/runner/hostedtoolcache/dncs/3.1.301/x64/sdk/3.1.301/Microsoft/WindowsXaml/v16.0/Microsoft.Windows.UI.Xaml.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/Users/runner/hostedtoolcache/dncs/3.1.301/x64/sdk/3.1.301//Microsoft/WindowsXaml/v16.0/Microsoft.Windows.UI.Xaml.CSharp.targets" is correct, and that the file exists on disk.
/Users/runner/work/MintPlayer.MVVM/MintPlayer.MVVM/Demo/MintPlayer.MVVM.Demo/MintPlayer.MVVM.Demo.iOS/MintPlayer.MVVM.Demo.iOS.csproj(140,3): error MSB4019: The imported project "/Users/runner/hostedtoolcache/dncs/3.1.301/x64/sdk/3.1.301/Xamarin/iOS/Xamarin.iOS.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/Users/runner/hostedtoolcache/dncs/3.1.301/x64/sdk/3.1.301//Xamarin/iOS/Xamarin.iOS.CSharp.targets" is correct, and that the file exists on disk.
/Users/runner/work/MintPlayer.MVVM/MintPlayer.MVVM/Demo/MintPlayer.MVVM.Demo/MintPlayer.MVVM.Demo.Android/MintPlayer.MVVM.Demo.Android.csproj(101,3): error MSB4019: The imported project "/Users/runner/hostedtoolcache/dncs/3.1.301/x64/sdk/3.1.301/Xamarin/Android/Xamarin.Android.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/Users/runner/hostedtoolcache/dncs/3.1.301/x64/sdk/3.1.301//Xamarin/Android/Xamarin.Android.CSharp.targets" is correct, and that the file exists on disk.
I then modified my workflow to use msbuild instead (at least until the build stage:
name: .NET Core
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1.5.0
with:
dotnet-version: 3.1.301
# Authenticates packages to push to GPR
source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
env:
NUGET_AUTH_TOKEN: '%NUGET_AUTH_TOKEN%'
- name: Install dependencies
#run: dotnet restore
#env:
# NUGET_AUTH_TOKEN: ${{ github.token }}
run: msbuild /t:restore
- name: Build
#run: dotnet build --configuration Release --no-restore
run: msbuild Library/MintPlayer.MVVM/MintPlayer.MVVM.csproj /p:Configuration=Release /p:RestorePackages=false
- name: Test
run: dotnet test --no-restore --verbosity normal
- name: Pack
run: dotnet pack --no-build --configuration Release MintPlayer.MVVM/MintPlayer.MVVM.csproj --output .
- name: PushNuget
run: dotnet nuget push *.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.PUBLISH_TO_NUGET_ORG }} --skip-duplicate
- name: PushGithub
#run: dotnet nuget push *.nupkg --source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json --api-key ${{ github.token }} --no-symbols --skip-duplicate
run: dotnet nuget push *.nupkg --no-symbols --skip-duplicate
env:
NUGET_AUTH_TOKEN: ${{ github.token }}
But it's still not working.
The console in Github actions prints the following error between the tons of text:
/Users/runner/.nuget/packages/msbuild.sdk.extras/2.1.2/Build/LanguageTargets/CheckMissing.targets(44,5): error : The specified language targets for uap10.0.16299 is missing. Ensure correct tooling is installed for 'uap'. Missing: '/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/xbuild/Microsoft/WindowsXaml/v16.0/Microsoft.Windows.UI.Xaml.CSharp.targets' [/Users/runner/work/MintPlayer.MVVM/MintPlayer.MVVM/Library/MintPlayer.MVVM/MintPlayer.MVVM.csproj]
So this probably means that the UWP tools aren't available on macos. From the output I can see that the android build succeeds, the iOS build succeeds, but the UWP build fails with the former message.
How can I build a Xamarin.Forms package in GitHub CI and push it to my nuget sources?
Edit:
Alright, I modified my workflow to use Windows and MSBuild
instead of macos and dotnet
, and this brings me a lot closer.
name: .NET Core
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1.5.0
with:
dotnet-version: 3.1.301
# Authenticates packages to push to GPR
source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
env:
NUGET_AUTH_TOKEN: '%NUGET_AUTH_TOKEN%'
# Add MsBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v1.0.1
- name: Install dependencies
run: msbuild /t:restore
env:
NUGET_AUTH_TOKEN: ${{ github.token }}
- name: Build
run: msbuild Library/MintPlayer.MVVM/MintPlayer.MVVM.csproj /p:Configuration=Release /p:RestorePackages=false /p:OutputPath=../..
- name: PushNuget
run: dotnet nuget push *.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.PUBLISH_TO_NUGET_ORG }} --skip-duplicate
- name: PushGithub
run: dotnet nuget push *.nupkg --no-symbols --skip-duplicate
env:
NUGET_AUTH_TOKEN: ${{ github.token }}
This action successfully pushes my nuget package to both Nuget and Github, but when I install this package in a Xamarin.Forms project, I'm only getting the UWP classes available in all of the projects, whilst these should only be available in the UWP-targetting project.
Unlike when I right-click my multi-targetting project and click the Pack command, the package does in fact work fine. Does anyone know how I can fix this?
This is my final workflow:
name: .NET Core
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1.7.2
with:
dotnet-version: 3.1.301
# Authenticates packages to push to GPR
source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
env:
NUGET_AUTH_TOKEN: '%NUGET_AUTH_TOKEN%'
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v1.0.2
- name: Install dependencies
run: msbuild /t:Restore
env:
NUGET_AUTH_TOKEN: ${{ github.token }}
- name: Build
run: |
msbuild /t:Pack /p:Configuration=Debug Library/MintPlayer.MVVM/MintPlayer.MVVM.csproj
dotnet pack Library\MintPlayer.MVVM.BaseModel\MintPlayer.MVVM.BaseModel.csproj --configuration=Release
- name: PushNuget
run: dotnet nuget push "**/*.nupkg" --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.PUBLISH_TO_NUGET_ORG }} --skip-duplicate
- name: PushGithub
run: nuget.exe push "**/*.nupkg" -NoSymbols -SkipDuplicate
env:
NUGET_AUTH_TOKEN: ${{ github.token }}