🐈⬛GitHub as a Source for NuGet
Last updated
Last updated
This guide will walk you through the process of adding GitHub as a source for NuGet packages in your project using the dotnet nuget add source
command. This is particularly useful if you host your own packages on GitHub or need to use packages that are not available on the official NuGet repository.
.NET SDK installed
A GitHub account with access to the repository containing the NuGet packages
Personal Access Token generated on GitHub
Navigate to GitHub Settings:
Log in to your GitHub account.
Click on your profile picture in the top right corner and select "Settings".
Generate a New Token:
In the left-hand menu, select "Developer settings".
Click on "Personal access tokens".
Click on "Generate new token".
Give your token a descriptive name and select the scopes you need. For accessing packages, you typically need the repo
, read:packages
, and write:packages
scopes.
Click "Generate token".
Important: Copy the token immediately as it will not be shown again.
Open Terminal or Command Prompt:
Open your terminal or command prompt.
Run the dotnet nuget add source
Command:
Replace YOUR_GITHUB_USERNAME
with your actual GitHub username.
YOUR_PERSONAL_ACCESS_TOKEN
with the personal access token you generated earlier.
Run the following command:
After successfully executing the command, if everything goes well, you should be able to see the newly added source in the NuGet Package Manager settings like shown in the following image:
You can verify the packages associated with your project on this link: Org-FoodService GitHub Packages
This confirms that GitHub has been successfully added as a source for NuGet packages in your project, and you can access the packages associated with the Org-FoodService
organization/repository using the provided link.
Restore Packages:
Navigate to your project directory in the terminal.
Run the following command to restore the packages:
Use the Packages:
You can now use the packages in your project as you would any other NuGet package. Simply add the necessary using
statements and start coding.