After a lot of trial and error I eventually got my NuGet package on the Github package registry with the following actions/commands:
- Go to GitHub
- Click your avatar (top-right) → Settings → Developer settings → Personal access tokens
- Generate a token with following scopes:
write:packages
,read:packages
,delete:packages
- This will automatically check the
repo
scope for your OAuth token
- Open cmd
- Navigate to your project directory or the directory containing your NuGet package
- Add a new nuget source
dotnet nuget add source --username [GithubUserName] --password [YourApiKey] --name github https://nuget.pkg.github.com/[UsernameOrOrganizationName]/index.json
- Push the package to the
github
sourcedotnet nuget push --source github bin\Release\MyAwesomePackage.1.0.0.nupkg
I can see my NuGet package on GitHub, so now I want to install it.
- I created a new project → Manage NuGet packages → Settings
- Add package source:
- Name: whatever
- Source: https://nuget.pkg.github.com/[UsernameOrOrganizationname]/index.json
Now I should be able to install my package. But when I select my source and browse for packages, a GitHub login window pops up. And even when I login with my user account credentials, I still can't access my packages (pushed to an organization Github). Now when I use the NuGet package manager for my custom package source I always get the following error in the Output Window
:
[source-name] Failed to retrieve metadata from source 'https://nuget.pkg.github.com/[UsernameOrOrganizationname]/query?q=&skip=0&take=26&prerelease=true&semVerLevel=2.0.0'. Response status code does not indicate success: 401 (Unauthorized).
The packages pushed to the GitHub registry should be public, and even with my user account I can't access them for installation. However they appear on my organization's GitHub page.Also the other users shouldn't have to add my personal GitHub package source, but rather the package should appear in some global GitHub feed inside the package manager, not?
What am I doing wrong?