I spent hours of searching and trying to get my NuGet packages on a private package server so I could use it on several computers and share them with colleagues. In this tip, I show you how easy it is - within 10 minutes, you have it done with a few simple steps.
Why
- You have class projects and create Nuget packages of them.
- Public sharing is no option.
- You want to share between computers and have it available centrally.
- Perfect, simple, easy to do.
This article describes:
- Personal
- Organization
1. Personal Private Packages on Github Package
Step 1
- Go to Github account >> Open Setting >> Developer setting >> Personal access tokens
- Get personal token <Api-Key>
- Get Github username <Github username>
Step 2
For sample, just create a new class project with .NET core or newer like at the command prompt as administrator.
dotnet new console --name OctocatApp
Step 3
In the project file, add in the tag propertygroup.
<RepositoryUrl>https://github.com/<Github username>/<ApplicationName>/</RepositoryUrl>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild><code>
- Replace <Github username>
- Replace <ApplicationName> (example:
OctocatApp)
Step 4
In the project root, create NuGet.Config
and copy the code below:
="1.0"="utf-8"
<configuration>
<packageSources>
<clear/>
<add key="github" value="https://nuget.pkg.github.com/<Github username>/index.json"/>
</packageSources>
<packageSourceCredentials>
<github>
<add key="Username" value="<Github username>"/>
<add key="ClearTextPassword" value="<API-Key>"/>
</github>
</packageSourceCredentials>
</configuration>
- Replace 2 x <Github username>
- Replace <API-Key>
Note
Version-number must be unique and unused. Change it in the project file or with project options.
Step 5
Push the application to GitHub (create a repo, or let VS do it for you).
Step 6
Open a command prompt as administrator in the project folder and type:
dotnet nuget push "bin/Release/<ApplicationName>.1.0.0.nupkg" --source "github"
- Replace <applicationName>
- Replace version-number
Finished
Check in Github packages and see your package.
Getting It
Add in VS a package source with https://nuget.pkg.github.com/<Github username>/index.json as source.
The first time, Github asks you the username/password.
2. Organization Private Packages on Github Packages
The project needs to be an organization project with members.
Step 1
- Go to Github account >> Open Setting >> Developer setting >> Personal access tokens
- Get personal token <Api-Key>
- Get Github username <Github username>
- Get OrganizationName <OrganizationName >
Step 2
For sample, just create a new class project with .NET core or newer like at the command prompt as administrator:
dotnet new console --name OctocatApp
Step 3
<RepositoryUrl>https://github.com/<OrganizationName>/<ApplicationName>/</RepositoryUrl>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
- Replace <OrganizationName >
- Replace <ApplicationName> (example:
OctocatApp)
Step 4
In the project root, create NuGet.Config
and copy the code below:
="1.0"="utf-8"
<configuration>
<packageSources>
<clear/>
<add key="github" value="https://nuget.pkg.github.com/<OrganizationName>/index.json"/>
</packageSources>
<packageSourceCredentials>
<github>
<add key="Username" value="<Github username>"/>
<add key="ClearTextPassword" value="<API-Key>"/>
</github>
</packageSourceCredentials>
</configuration>
- Replace <Github username>
- Replace <OrganizationName >
- Replace <API-Key>
Note
Version-number must be unique and unused. Change it in the project file or with project options.
Step 5
Push the application to GitHub (create a repo, or let VS do it for you).
Step 6
Open a command prompt as administrator in the project folder and type:
dotnet nuget push "bin/Release/<ApplicationName>.1.0.0.nupkg" --source "github"
- Replace <applicationName>
- Replace version-number
Finished
Check in Github packages and see your package.
Getting It
Add in VS a package source with https://nuget.pkg.github.com/<Github username>/index.json as source.
The first time, Github asks you the username/password.
Happy coding!
History
- 16th January, 2021: Initial version