JandaBox NuGet Class Library - Jandini/JandaBox GitHub Wiki
Create NuGet package and push to GitHub/NuGet.org package registry.
-
Create new GitHub repository.
-
Create GitHub access tokens and/or API key in NuGet.org and save it as secrets in the new repository.
-
Create new Project from the template and push it to GitHub.
dotnet new nugetbox -n MyNuGet --actions --user Jandini --gitVersion cd MyNuGet git init -b main git add . git commit -m "First commit" git remote add origin https://github.com/Jandini/MyNuGet.git git push -u origin main
At this point GitHub actions will create NuGet package and push it to GitHub private package registry. The package is created and pushed only for main branch.
- A new tag will trigger NuGet pipeline which will create and push release package to GitHub or NuGet.org. Use
--tagNugetOrgparameter to push release package to nuget.org. Nuget.org API key is required in repos' secrets.
Read more on how to use GitHub NuGet registry in GitHub actions here https://docs.github.com/en/actions/security-guides/automatic-token-authentication
Step by step
- Create new GitHub repository
- Go to https://github.com/new and create public or private repository.
- Do not add any files at this stage.
- Your repository URL should look like https://github.com/Jandini/MyNuGet.git where
Jandiniis going to be your user name.
Following step can be skipped if you have safely stored your PAT which can be re-used.
- Create Personal Access Token (PAT) with
write:packagespermissions. This will allow to push NuGet packages into GitHub package registry.- Go to https://github.com/settings/tokens and from drop down "Generate new token" select "Generate new token (classic)" or go directly to https://github.com/settings/tokens/new
- Set "Note" to anything you want. Usually it should reflect purpose of the token.
- Select checkbox "write:packages" to allow upload packages to GitHub Package Registry.
- Click "Generate token"
- Copy the new token to clipboard. Note: you will see the token only once.
- Add token to repository secrets as PACKAGE_REGISTRY_TOKEN.
Following steps explains how create API key in https://www.nuget.org/. If you are planning to push your release packages to nuget.org then you must use --tagNugetOrg parameter when creating project from template and perform following steps.
-
Go to https://www.nuget.org/ and login to your account.
-
Under "API Keys" create new token or go directly to https://www.nuget.org/account/apikeys
- Specify "Key Name"
- You can specify pattern name for your NuGet package or use
*to allow push for any package - Click "Create"
- Copy the Key into clipboard
-
Add NuGet API Key to Secrets in GitHub repository.
-
Go To "Actions secrets and variables"
- Open repository Setting
- In the left hand side, under Security select Secrets and variables | Actions
-
Click "New repository secret"
-
Paste your NuGet API Key into "Secret*" field
-
Secret's "Name" must be set to
NUGET_ORG_API_KEY. This name is used innuget.ymlfile. -
Click "Add secret"
-
-
Create new project from
nugetboxtemplate.- Give it a name
-n MyNuGet - Add GitHub Actions
--actions - Provide your GitHub user name
--user Jandini - Add versioning with GitVersoin
--gitVersion
dotnet new nugetbox -n MyNuGet --actions --user Jandini --gitVersion - Give it a name
-
Initialize local git repository and push it to GitHub
cd MyNuGet git init -b main git add . git commit -m "First commit" git remote add origin https://github.com/Jandini/MyNuGet.git git push -u origin main
That's all. Your NuGet package will be waiting in GitHub registry !
Template options
--nugetAdd properties to project file required to build and push NuGet package. Default value istrue. Usefalseto create simple class library.--userSpecify GitHub user name to update links in project file properties and GitHub action badge links in README.md file.--actionsAdd GitHub Actions pipeline files for building and pushing NuGet packages. Build pipeline creates NuGet package and push it to private GitHub packages only formmainbranch. NuGet pipeline creates NuGet package and push it to NuGet.org package registry. Default value isfalse.--tagNugetOrgAdd GitHub action file to push tagged NuGet packages to NuGet.org registry. By default tagged packages are pushed into of GitHub package registry.--gitVersionAdd semantic versioning with GitVersion. The code created with this parameter can be only build from initialized git repository.--licenseAdd MIT license file to the NuGet package with authors provided in--authorsparameter.--authorsAdd NuGet package authors. The authors will be written to package properties and license file.
Template features
- Repository Layout
- The
srcandbinfolders - Default
README.mdfile - Default
.gitignorefile
- The
- NuGet configuration
- Build NuGet package with only
dotnet pack
- Build NuGet package with only
- GitHub Actions
- Restore packages from private GitHub package registry.
- Pack library into NuGet package.
- Push NuGet package created from main branch into NuGet package registry.
- Push Tagged package into NuGet.org or GitHub package registry.
- Update links in project properties
RepositoryUrlPackageProjectUrland badge links inREADME.mdfiles. - Add files into the NuGet package
- README.md
- MIT LICENSE with given authors
- Icon file