Skip to content

NuGet Package Publishing Guide

This guide provides step-by-step instructions for publishing NuGet packages to GitHub Packages for this repository.

1. Create a Personal Access Token (PAT) for GitHub Packages

  • Go to https://github.com/settings/tokens to manage or create your Personal Access Tokens.
  • Go to your GitHub account settings.
  • Navigate to Developer settings > Personal access tokens > Tokens (classic).
  • Click Generate new token.
  • Give your token a name and select an expiration date.
  • Under Select scopes, check at least:
  • repo
  • write:packages
  • read:packages
  • Click Generate token and copy the token. You will not be able to see it again!

2. Add the PAT as a GitHub Actions Secret

  1. Go to your repository on GitHub.
  2. Click Settings > Secrets and variables > Actions.
  3. Click New repository secret.
  4. Name the secret NUGET_PUBLISH_TOKEN.
  5. Paste your PAT as the value and save.

3. Update Nuget.config (for local development)

If you want to push packages from your local machine, add your PAT to your Nuget.config:

<configuration>
  <packageSources>
    <add key="Luckbox" value="https://nuget.pkg.github.com/<OWNER>/index.json" />
  </packageSources>
  <packageSourceCredentials>
    <Luckbox>
      <add key="Username" value="<YOUR_GITHUB_USERNAME>" />
      <add key="ClearTextPassword" value="<YOUR_PERSONAL_ACCESS_TOKEN>" />
    </Luckbox>
  </packageSourceCredentials>
  <packageSourceMapping>
    <packageSource key="Luckbox">
      <package pattern="LBS.*" />
      <!-- Match the GitHub packages you reference -->
    </packageSource>
  </packageSourceMapping>
</configuration>
- Replace <OWNER> with your GitHub username or organization. - Replace <YOUR_GITHUB_USERNAME> and <YOUR_PERSONAL_ACCESS_TOKEN> with your credentials.

4. Publishing from CI/CD (GitHub Actions)

  • The workflow uses the NUGET_PUBLISH_TOKEN secret to authenticate and push packages.
  • No manual update to Nuget.config is needed for CI/CD; it is handled by the workflow.

5. Publishing from Local Machine (Optional)

  1. Ensure your Nuget.config is updated as above.
  2. Run the following commands:
    dotnet build <YourProject>.csproj -c Release
    dotnet pack <YourProject>.csproj -c Release -o ./nupkgs
    dotnet nuget push ./nupkgs/*.nupkg --source "github"
    

For more details, see the GitHub Docs: Publishing a package.