Reputation: 473
I'm getting a "Specified source 'github' is invalid" error when trying to build and push a NuGet package to GitHub NuGet Packages.
Does anyone know why, or what the source should be? I can't see anything in the GitHub documentation about this value, or even the end URL that will host my packages (I'm hoping it will just show in the packages tab when one is created).
I have just seen that GitHub has Actions now, so you can get your code to build/test when changes are merged. I have also seen that you can now also publish a NuGet package and host it within GitHub too. Looking at the screenshot below, it seems it should be quite easy to do:
It took me a while to realize I needed to create an Action to put this code into, so here is my action code (YAML):
This action runs when I commit, and it all passes until the last line for pushing to GitHub. I get an error on the last line:
The specified source 'github' is invalid. Please provide a valid source
Upvotes: 3
Views: 2712
Reputation: 2820
The reason is because github
is not defined in the --source "github"
command.
The documentation (https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry) isn't very clear. In order to publish to the same GitHub NuGet repository, do something like the following in your YAML:
- run: dotnet nuget add source --username shiraze --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/shiraze-company/index.json"
- run: dotnet nuget push "MyPackage.1.1.0.nupkg" --source "github"
My username is shiraze
, so replace that with yours. I'm publishing to a private GitHub NuGet repository, so replace shiraze-company
either with the organisation you wish to publish to, or your username (to publish to your own profile).
This route doesn't require you to create a Personal Access Token (PAT). You will need a PAT, though, when restoring private NuGet repositories - as documented on the above page.
Upvotes: 3
Reputation: 16056
You'll need to add GitHub as a resource in your Nuget configuration
you can use the following command line:
dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/OWNER/index.json"
where GITHUB_TOKEN could be a PAT token as well, check more information in the official documentation.
That command line will append the source to your config file
Upvotes: 2
Reputation: 4412
Well, what is your NuGet.Config
? I would imagine given the error message that there is no source in it named github
. You need to publish to a source that actually exists in your configuration, otherwise how does nuget
know where to publish to?
An example NuGet.Config
file might look like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="SomeOtherSource" value="https://some.source.maybe.jfrog.com/nuget/nuget-local" />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
If you don't have a source with key="github"
, your command will fail.
You can find more information on GitHub Packages w/NuGet here
Upvotes: 1