Install NuGet package from GitHub Package Registry - nuget-package

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 source
dotnet 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?

It appears that righg now it's not yet possible: https://github.community/t/download-from-github-package-registry-without-authentication/14407/39

First, make sure that your credential info is correct on the nuget.config file.
If you want to config this github package source for all the projects on your PC, you should config it on the global nuget.config file.
please add your content of the file into C:\Users\xxx(current user)\AppData\Roaming\NuGet\NuGet.Config.
restart VS Instance or restart PC to enable this new nuget.config file. It is designed by that.

Related

Github Package: Key not valid for use in specified state

I am unable to use the package published by another user.
Process:
Added the new package name and source by updating the nuget.config
Added the package source username and password(APIKey)
Tried added the NuGet package generated by admin account though NuGet package manager but not able to see it.
Giving error:
Feeds used:
https://api.nuget.org/v3/index.json
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
https://nuget.pkg.github.com/account/index.json
NuGet package restore finished.
Key not valid for use in specified state.
Any Ideas?

How to download NPM package published to GitHub packages registry as a zip?

I am using GitHub packages to publish my private NPM packages. I need to download the published package of specific version for carrying out automation work. How can I download the package as a zip bundle using GitHub REST API or equivalent? Additionally, since it is a private package, it needs to be authenticated.
I know that equivalent functionality exists but it works for GitHub releases and assets. I could not find anything yet for GitHub packages!
After a few days of intermittent research regarding this question, here is what I have found. There seem to be two methods of retrieving and/or consuming privately published NPM packages from the GitHub Package Registry. And neither of them is an exact match to your desired method, so, here goes...
OPTION 1.
You can consume the npm package directly within your application provided you have a locally configured .nprmc file on your machine in your user directory (check first #~/.npmrc),
AND
you have created a GitHub personal access token with the following scopes.
repo: full (this is how you will be authenticated.)
workflow
write: packages
adminOrg: read
user: email
NOTE: You may not require all of these, but these are the permissions I used and had no issues. Once you generate the token, create or add it to your .npmrc file like so, replacing TOKEN with the actual token value.
//npm.pkg.github.com/:_authToken=TOKEN
Be sure you additionally add the following snippet into the project or container itself within another .npmrc file in the root directory of the codebase.
#YOUR_GITHUB_USERNAME:registry=https://npm.pkg.github.com
OPTION 2:
You can connect your package to a private GitHub repository, which will allow you to access the tar.gz artifact for each version of your package and directly download it to your local machine from the web.
github.com > Your profile > Packages > Connect repository > Select and link.
REFERENCE: How to publish packages to the GitHub Package Registry

How do I set up GitLab runner to pull from a private NuGet repo on build of my project?

How do I set up GitLab runner to pull from a private NuGet repo on build of my project? For example I have a project using a package from Telerik. When I created the yaml file and tell the CI to build it fails with error unable to find package Telerik.UI.for.Blazor. No packages exist with this id in source(s): nuget.org. I also have a private repo on one of our company servers that I would need to pull packages from.
I have found a solution to this, not sure it is the best solution. I added a NuGet.config file with the package source and credentials as suggested in these links.
https://docs.telerik.com/aspnet-core/getting-started/first-steps-cli
https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file#example-config-file
The project now pulls the dll from Telerik and builds. Only problem is my Telerik creds are now in GitLab.

Not able to install npm packages after placed the private `.npmrc` file in Azure

I'm not able to install packages from npm, since I have placed a .npmrc file for install a private library.
This library is hosted by azure work space.
So i just placed the new config file to install. And it works fine in localhost.
How can i keep 2 registry in nprmc file, one for private and another one of npm registry?
error 404 Not Found - GET https://registry.npmjs.org/mm-core - Not found
mm-core is my private library hosted in azure, without my .npmrc file i receive this error.
With .npmrc file npm packages can't be installed.
any help?
It actually should work if you follow the official documents correctly. And we don't need to keep 2 registry in nprmc file, one for private and another one of npm registry.
Solution:
Keep the .npmrc file which presents the azure devops artifacts feed. And sign-in the azure devops web portal to configure the feed settings:
In feed settings, go Upstream sources and make sure you have npmjs as Upstream source. If it not exists, click the Add upstream source to add npmjs.
Then you only need to hold one registry for private library. If the package is not found in your private feed, since we've configured npmjs as upstream source, it will fetch the missing package there automatically!
More details about magic upstream source please refer to this document.

Cannot pack fork of azure-activedirectory-library-for-dotnet into nuget package

I made a fork of the library azure-activedirectory-library-for-dotnet and tried to pack it into a nuget package but failed.
I run the following command on the Developer Command Prompt to try to pack my fork into a nuget package.
nuget Pack src\Microsoft.IdentityModel.Clients.ActiveDirectory\Microsoft.IdentityModel.Clients.ActiveDirectory.csproj
And this is the error I get when I run this command:
Unable to find 'bin\Debug\Microsoft.IdentityModel.Clients.ActiveDirectory\bin\Debug\'. Make sure the project has been built.
But the project is build succesfull and contains the following folder in the debug folder:
My fork github page
The page where the original azure project is stored: Github azure
Link to issue I created on the github page: Issue

Resources