Getting Github Nuget Package Repo Working
It should be simple ... but its not
Today we decided to move a library into a nuget package. However this time we decided to use github actions and github package repository. We also haven’t had to publish a nuget package in a long time simply due to favouring monorepos and always looking to innovate in areas others have not already done the work!
We expected this to be a 10 minute job. It ended up taking a large part of a day.
Nuget config files
There are several places these can live (especially on non windows systems). Rider for instance looks in .nuget
whereas the nuget docs claim .config/Nuget
. I will be honest, we ended up simply pasting the config to both places.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="dinoroar" value="https://nuget.pkg.github.com/DinoRoar/index.json" />
<add key="mrtortoise value="https://nuget.pkg.github.com/MrTortoise/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<packageSourceCredentials>
<dinoroar>
<add key="Username" value="MrTortoise" />
<add key="ClearTextPassword" value="<Create a personal access token>" />
</dinoroar>
<mrtortoise>
<add key="Username" value="MrTortoise" />
<add key="ClearTextPassword" value="<Create a personal access token>" />
</mrtortoise>
</packageSourceCredentials>`
</configuration>
Creating a personal access token involves goign to github settings for you user, clicking developer settings and then adding a personal access token with write:packages
How to build and publish
In the project there is some setup of nuget required.
I setup the package id, title and repository url eg https://github.com/[org/user]/[repo name]
then to package
dotnet pack /p:Version="0.0.5" [projectdirectory]
dotnet nuget push [path to nupkg file]]0.0.5.nupkg -s dinoroar
and now you have a package on github.
but but thats no help for CI
So github ….
This was the time sink.
I’ll just include the YAML as really setup was zero it was a lot of thrashing discovering where to put the settings.
name: .NET Core
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Generate build number
id: buildnumber
uses: einaregilsson/build-number@v2
with:
token: $
- name: Print new build number
run: echo "Build number is $BUILD_NUMBER"
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.101
source-url: https://nuget.pkg.github.com/[companyusername]/index.json
env:
NUGET_AUTH_TOKEN: $
- name: Install dependencies
working-directory: [base folder for solution file ...]
run: dotnet restore
- name: Build
working-directory: [base folder for solution file ...]
run: dotnet build --configuration Release --no-restore
- name: Test
working-directory: [base folder for solution file ...]
run: dotnet test --no-restore --verbosity normal
- name: Pack
working-directory: [base folder for solution file ...]
run: dotnet pack /p:Version="0.0.$" [project folder path]
- name: Push
working-directory: [base folder for solution file ...]
run: dotnet nuget push E[path_to_nupkg]0.0.$.nupkg -s https://nuget.pkg.github.com/[companyusername]/index.json
bit of a mess but works