I'm trying to create a NuGet package of my .NET library and publish it to GitHub Packages NuGet registry using GitHub actions.
I'm stuck at the publish part. I'm using the following command:
dotnet nuget push "bin/Release/MyApp.${{ steps.get-version.outputs.version }}.nupkg" source --username MY_GITHUB_USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/MY_COMPANY_GITHUB_ACCOUNT/index.json"
The error I'm getting is:
Unrecognized option '--username'
As you may have noticed, I'm getting the version number I set in .csproj
file in order to figure out the nuget file name.
What command do I need to issue to push my NuGet package into my private GitHub Packages registry after building it?
Here's the full release.yml
file:
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
name: Publish MyApp NuGet to GitHub Packages
on:
pull_request:
branches: [ "master" ]
jobs:
build-pack-n-ship:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Create NuGet package
run: dotnet pack --configuration Release
- name: Get version
uses: kzrnm/get-net-sdk-project-versions-action@v1
id: get-version
with:
proj-path: MyApp/MyApp.csproj
- name: Add GitHub Packages as Source
run: dotnet nuget add source --username MY_GITHUB_USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/MY_GITHUB_COMPANY_ACCOUNT/index.json"
- name: Publish to GitHub Packages
run: dotnet nuget push "bin/Release/MyApp.${{ steps.get-version.outputs.version }}.nupkg" --source github
I usually just add
source
and then when push I just set--source
.