How do I publish NuGet packages to GitHub Package Registry using dotnet on Mac?

Viewed 2889

The documentation is not complete and currently I cannot consume or publish package to GPR using dotnet on Mac. Any help would be useful

3 Answers

Far from ideal, and I haven't tested on Mac yet, but it worked on Linux

Publish

  • Enable GPR 'feature' in your GitBHub settings
  • Go to github and add a TOKEN with GPR read/write access
  • Add source locally

    nuget source Add -Name "GitHub" \
      -Source "https://nuget.pkg.github.com/MY_ACCOUNT/index.json"
    
  • Set api key

    nuget setApiKey $TOKEN \
        -Source "https://nuget.pkg.github.com/MY_ACCOUNT/index.json"
    

Push package

    nuget push "my.lib.nupkg" -Source "GitHub"

Install package

    nuget install my.lib -pre # '-pre' because of alpha, if alpha
Note:  
'nuget install' downloads the nuget package  
It doesn't add it to the project.  
'dotnet' can't find it  
Do it anyway so it gets cached in `~/.nuget/packages`
The `./project` relative downloaded package can be deleted  

Reference manually:

Add 'new Source' to nuget.config.

<add key="GitHub" value="https://nuget.pkg.github.com/MY_ACCOUNT/index.json" />

nuget config can be

  • './nuget.config'
  • '~/.nuget/NuGet/nuget.config'

Add to project:

    dotnet add package my.lib \            
        -v 1.0.0-alpha \
        -n # don't download, it can't handle authentication

Alternatively:
Edit project package reference

<PackageReference Include="my.lib" Version="1.0.0-alpha" />

Finally:

dotnet restore 

As you can see at this link to the github community question dotnet nuget is currently not supported by the GPR and you rather have to use nuget with Mono or publish from Windows.

I hope they'll fix it in the near future myself, it's completely stopping me from taking advantage of the GPR.

You'll have to make the HTTP call yourself (other steps omitted for brevity):

jobs:
  continuous-integration:
    runs-on: ubuntu-latest
    steps:
    - name: push
      run: |
        for f in ./packages/*.nupkg
        do
          curl -vX PUT -u "<YOUR USER NAME>:${{ secrets.GITHUB_TOKEN }}" -F package=@$f https://nuget.pkg.github.com/<YOUR USER NAME>/
        done
      if: github.event_name == 'push'
Related