Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 432
junkie011235 Avatar asked Jan 26 '23 18:01

junkie011235


2 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 
like image 105
Dan Avatar answered Apr 25 '23 21:04

Dan


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.

like image 35
Mortimer Avatar answered Apr 25 '23 22:04

Mortimer