0

I've succeeded in setting up a GitHub action that builds and packs my multi-target NuGet package.

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%'
    
    - name: Setup MSBuild
      uses: microsoft/setup-msbuild@v1.0.1
    
    - 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
    
    - name: Copy
      run: copy Library/MintPlayer.MVVM/bin/Debug/*.nupkg .
    
    - 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 }}

Since this is a Xamarin.Forms package, I need to use the MSBuild SDK.

The restore, build and pack commands are working fine. I cannot use the p:OutputPath parameter for multi-target nuget packages (Issue can be tracked here). That's why I have a step to build, and copy the file to the %cd%.

The push to nuget.org works as expected, but the push to my github feed fails with the following result:

Output of the push to github feed

I cannot find out what's going wrong here. Does anyone have an idea of why the push to GitHub is failing?

Also here is an example of a successful push to GPR, so the warning about the API key not being provided is not the cause of the issue:

Successful push to GitHub Package Registry

(Same question on github.community)

Pieterjan
  • 2,738
  • 4
  • 28
  • 55
  • Maybe give `gpr push` tool a try https://github.community/t/github-package-registry-not-compatible-with-dotnet-nuget-client/14392/19 and see if that helps – Edward Romero Sep 07 '20 at 20:43
  • There's also some different ways to push to GPR over here (e.g. curl): https://stackoverflow.com/questions/57889719/how-to-push-nuget-package-in-github-actions. – riQQ Sep 07 '20 at 20:49
  • I've read these approaches, they seem to be outdated. For example you don't have to generate a token and put it in the `secrets`, but instead you can use `github.token`. Also you don't need to use `dotnet nuget add source` anymore, the `setup-dotnet` action handles this for you. The only thing in my case that doesn't work is the push to Github packages. It does not explicitly say that it cannot authenticate the request, so I doubt that this would be the issue... – Pieterjan Sep 07 '20 at 21:02
  • Also [here is the workflow for another project](https://github.com/MintPlayer/MintPlayer.SeasonChecker/blob/master/.github/workflows/dotnet-core.yml). This one works as expected and is able to push to GPR. Also tried with %NUGET_AUTH_TOKEN% but no luck – Pieterjan Sep 07 '20 at 22:13
  • 1
    Check the release notes in your project. It has happened to me before that using characters like `(, ), '` in the tag `PackageReleaseNotes` makes the package publishing fails. – Yasel Sep 10 '20 at 15:02
  • Thanks for the tip. I did remove my `PackageReleaseNotes` from my csproj-file, did the same for the `PackageTags`. Sadly with no avail. I think it started to fail when I made my package multi-target (`TargetFrameworks`) – Pieterjan Sep 11 '20 at 07:31
  • 1
    I believe this has to do with the size of the package, see here: https://github.community/t/push-nuget-package-to-github-com-the-response-ended-prematurely-an-error-occurred-while-sending-the-request/131032/10 – Chad Kapatch Sep 16 '20 at 15:56

1 Answers1

0

In case of dead links: It seems that right now, when you want to push the package to your GitHub feed, you can use nuget.exe instead of dotnet nuget to workaround the problem.

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%'
    
    - name: Setup MSBuild
      uses: microsoft/setup-msbuild@v1.0.1
    
    - 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
    
    #- name: Test
    #  run: dotnet test --no-restore --verbosity normal
    
    - 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 }}

This also seems to fix the ignored --skip-duplicate flag for GPR. Also don't use the p:OutputPath or output-path option in your step, since for a multi-target nuget package this only packs the UWP-target DLL.

Pieterjan
  • 2,738
  • 4
  • 28
  • 55