GitHub Actions: automatically push NuGet package #26906
-
stackoverflow.com
GitHub Actions: automatically push NuGet package
nuget-package, github-actions, github-package-registry
asked by
Pieterjan
on 02:39PM - 19 Aug 20 UTC
I’m trying to configure my Github repository in order to automatically have a NuGet package built and pushed to both nuget.org and github.com. So what I want is that each time a commit is made on the master branch, or another branch is merged into the master, github publishes a new Nuget package of the head of the master to both Nuget and Github. NuGet
Github
These are the scopes for my Github access token: SetupIn my github repository I’ve setup an action to restore, build, test, pack and publish:
The push to nuget.org works fine, but the push to my GitHub feed fails with an Unauthorized error. I’ve taken a look at some plugins like this one, and I want to embed this into my action in order not to build my project multiple times. First take:
Second take with multiple commands:
This one fails with the following (obvious) message:
Does anyone have any experience with automated publishing of Nuget packages to Github? Link to action configuration file EditI tried sending a POST request:
And I’m getting my user information, so my access token definitely works. |
Beta Was this translation helpful? Give feedback.
Replies: 12 comments 1 reply
-
Also when I visit https://nuget.pkg.github.com/MintPlayer/MintPlayer.SeasonChecker/index.json in my webbrowser, I get a login prompt and after signing in with a PAT (and not my password) I get the information for my NuGet package. So my PAT definitely works. Does anybody have an idea how to solve this? |
Beta Was this translation helpful? Give feedback.
-
Instead of using,
This should work to associate your package with the same repository as the workflow. You only need to create a PAT if you’re associating it with a different repository. I hope that helps! |
Beta Was this translation helpful? Give feedback.
-
Hi, I’ll try that. So if I understand correctly, the |
Beta Was this translation helpful? Give feedback.
-
Sweet, It’s working now.
Very nice implementation. Thanks for the help. |
Beta Was this translation helpful? Give feedback.
-
PieterjanDeClippel:
The I’m glad it’s now working! Let me know if you notice any other issues. |
Beta Was this translation helpful? Give feedback.
-
It still doesn’t seem to be working correctly. GitHub succeeded in pushing the package the first attempt. But when I made another change + version increment, the Action fails again, this time at the It appears that dotnet is trying to restore ALL packages from my own NuGet source now, instead of the source where they are hosted.
So dotnet looks for How can I fix this? |
Beta Was this translation helpful? Give feedback.
-
What does your |
Beta Was this translation helpful? Give feedback.
-
Right now there’s no MintPlayer/MintPlayer.SeasonCheckerFind out the season for a date. Contribute to MintPlayer/MintPlayer.SeasonChecker development by creating an account on GitHub. Are you aiming at defining my package sources for the action? Right now on my computer I’m using the system-wide package sources. So when I run
command from anywhere the list of sources is shown (including my own nuget feed). Should I create a nuget.config like this containing my own nuget feed, and remove the |
Beta Was this translation helpful? Give feedback.
-
Okay that was it. I added a nuget.config to my solution folder
And now my deployment is working fine. Thanks a lot for the help |
Beta Was this translation helpful? Give feedback.
-
PieterjanDeClippel:
I think it was trying to restore from both, but GitHub Packages was failing because Could you try changing the
BTW, it is possible to pass the token directly to |
Beta Was this translation helpful? Give feedback.
-
Piggybacking off of this. I have implemented a near identical solution that pushes multiple packages, but the --skip-duplicate flag is ignored while pushing and causes a failure. Is there a reason why that flag would be ignored? |
Beta Was this translation helpful? Give feedback.
-
@joelrevans I switched from
to
And now the step does not error when attemting to push a duplicate package. I needed to switch to nuget.exe because of this |
Beta Was this translation helpful? Give feedback.
Hi @PieterjanDeClippel,
Instead of using,
dotnet nuget add source
, you can use thesetup-dotnet
to create the appropriatenuget.config
file. For example"This should work to associate your package with the same repository as the workflow. You only need to create a PAT if you’re associating it with a different repo…