Can I ignore this nuget warning about no API KEY? - nuget

When pushing I see this:
nuget push blah.1.0.0.nupkg -source repo
WARNING: No API Key was provided and no API Key could be found for 'https://meeee.jfrog.io/meeee/api/nuget/repo'. To save an API Key for a source use the 'setApiKey' command.
Pushing blah.1.0.0.nupkg to 'https://meeee.jfrog.io/meeeee/api/nuget/repo'...
PUT https://meeee.jfrog.io/meeee/api/nuget/repo/
Created https://meeee.jfrog.io/meeee/api/nuget/repo/ 8585ms
Still works and it has to be using the API key because otherwise I'd get access denied - so I'm not sure what it's warning me about. Maybe because I don't have a default machine wide API key? I had to add the nuget source with user name and password because nuget is a mess and won't pull the default API key for it without setting it for each source.
Also I noticed even if I upload the same exact package a bunch of times in a row it still uploads it - I thought maybe Artifactory would see it was the same and not upload or tell me that?

You probably have your credentials specified in your nuget.config file for repo to authenticate.
To get rid of the warning, simply specify a dummy API key using --api-key 0 in your request.

The warning went away for me after using the following nuget command:
nuget setapikey YOUR_API_KEY -source YOUR_SOURCE_NAME

Related

How to specify an API Key when publishing to a private nuget source in Azure Devops?

I am trying to publish a NuGet package to a NuGet feed I created in Azure Devops. I have experience in doing these kind of things (I published on NuGet.org) but for some reason I do not understand, it is not working when I try to do this for my employer.
When I click "Connect To Feed", I see this explanation:
This clearly shows where to put my package path and where to put the source. However, it does not show where to put the API key I generated.
But I gave it a try and typed (after generating the package file):
dotnet nuget push --source "Test" --api-key az ClassLibrary1.1.0.0.nupkg
This was not working (401)
I really do not understand this part of the explanation: "API Key (any string will do)". Why possibly "any string will do". I need a valid API key.... Not "any string".
After that I tried to publish in way I have good experience with (when publishing nuget.org public nuget packages). In this statement, the source and key are clearly specified.
Here is how I did it:
Also that does not work. I got a 401 again.
My API key that should give me access (and thus prevents a 401) should be fine. This is how I generated the API key:
Most likely, there is something wrong with the way I specified my API key, not with the API key itself. So how do I specify it correctly in my command-line statement in order to successfully publish my package?
There are a few steps you'll have to take before you can push to your NuGet feed locally:
Install the Azure Artifact Credential Provider: https://go.microsoft.com/fwlink/?linkid=2099625
Run dotnet restore --interactive, this will prompt you for credentials
Run dotnet nuget push --source "BackgroundJobs" --api-key anyapikey <package-path>
Note: You can use any API key.

Unable to PUSH nupkg to the existing feed in Azure DevOps

I'm trying to PUSH a nupkg to exisiting Feed in Azure DevOps. When I do it using Powershell scripts, I get the error 'The Specified source is invalid.Provide a valid source' even though the source is valid. When I try to recreate a source with the below command, It gives me error 'The source specified has already been added to the list of available package sources. Provide a unique source.'
According to the NuGet push command reference, the Source option value should be a URL. Besides, the order of the command line options might be different.
I would try to re-write it as follows:
nuget.exe push ALS.Library.1.0.0.nupkg -Source "http://..." -ApiKey "..."

Nuget Push always returning 404 (Not Found)

I've tried to publish a nuget package to my GitHub Packages account but in all cases I'm having the 404 error.
I've followed as requested on the GitHub's site:
nuget source Add -Name "GitHub" -Source "https://nuget.pkg.github.com/[MyAccount]/index.json" -UserName [MyUserName] -Password GH_TOKEN
It throwed me an error saying to add an api key.
So I created a Personal Access Token and set the api key:
nuget setapikey [MY_PAT_TOKEN] -Source "https://nuget.pkg.github.com/[MyAccount]/index.json"
But when trying to push again I had:
"Your request could not be authenticated by the GitHub Packages
service. Please ensure your access token is valid and has the
appropriate scopes configured."
So I created another token with the necessary scopes:
- read:packages
- write:packages
- delete:packages
- repo
I deleted the source and the api key and started the steps above again, with the new token, but I had the 404 error, saying that the source was not found.
So I've tried a lot of options... changing package name, changing source name, and a bunch of other things, but with the same result.
So I read this on the GitHub's website:
"When you publish a package, by default GitHub Packages uses the
package name to determine the GitHub repository containing the
package. For example, a package named odata-client would be published
to the OWNER/odata-client repository. If you would like to change the
repository containing the package, or publish multiple packages to the
same repository, you can include the URL to the GitHub repository in
the repository field of the package's .nuspec file."
As I'm using .NET Core 3.0 so I changed the csproj including:
<RepositoryUrl>https://nuget.pkg.github.com/[MyAccount]/Common</RepositoryUrl>
<RepositoryType>git</RepositoryType>
But this time I had a 400 (Bad Request)
And I tired some variations for the above url: ending with index.json, ending without index.json, ending with common, etc... But always have Bad Request error.
So I deleted this configurations and tryied again: 404 (Not Found)
I don't know what to do any more. There are someone that can help me with that? What am I doing wrong? It lacks some configuration?
I had same issue. For me it was wrong Repository Url in nuget package. I would advise you to check that RepositoryUrl is set and it is a valid url of existing repo.
I have been fixed the same error setting my repository URL:
<PropertyGroup>
<!--Others configurations values-->
<RepositoryUrl>https://github.com/GITUSERNAME/REPOSITORY-PATH**</RepositoryUrl>
</PropertyGroup>
I am using dotnet core and setting this configuration in .csproj
I had the same issue, my solution was to give all "Repo" permissions to the token.
PS: my Repo was private
I had the exact same issue and struggled with it alot.
I ended up using some of your pointers - adding
to my .nuspec and packed the project again.
This helped and pushing to github worked.
Please try packing your project again.

Nuget with Artifactory. Key not valid for use in specified state

I am using Artifactory as NuGet repository to store all the nuget packages.
When we use this Artifactory link as source, the package Manager in Visual Studio prompts for credentials and worked very fine.
As soon as we moved to build machine (with out VS) and try to build application it is throwing error :
.nuget\NuGet.targets(100,9): error : Key not valid for use in
specified state.
I added source with -user -password and put config at local user location. I tried with ClearText password and encrypted password both are throwing same error.
Am I missing anything here? Please advice.
I believe the error isn't related to Artifactory.
The issue NuGet reports is related with encrypting/decrypting user credentials in nuget.config files.
I encountered the error when I tried to set apiKey for a repo:
NuGet setapikey user:pwd -Config .\NuGet.test.Config -Source .\packages
NuGet reported "Key not valid for use in specified state".
I had NuGet.config file located near NuGet.test.Config. That nuget.config contained packageSourceCredentials section with credentials of other user (than one which was passed to setapikey).
After I remove that credentials from nuget.config the error gone.
Please check Nuget.Config in %AppData%\NuGet
You may want re-create it in order to resolve the issue.
FYI, I had the same problem with my build agent, the issue is resolved by removing "nuget.config" in "C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\NuGet"
I encountered the same error when I logged into Windows using a new user account (story: our network admin at our company had removed our users due to an infection by a ransomware and created a new user account for each of us).
We have a local nuget server at our company (created using free Nuget Server).
As #Jinsoo stated, I needed to remove the nuget settings in Nuget.Config (at %AppData%/Roaming/Nuget folder) and set again the apikey for our nuget source using such a command:
nuget setApiKey abcdefghijklmn -Source http://www.our-company-nuget-server.com/nuget
After that I was able again to issue 'nuget push' commands.
Got this issue in TeamCity after adding a global nuget config to the build servers.
Had to change to a newer version of nuget.exe in the build configs, as the old version probably could not cope with some setting in the nuget config.
I had the same problem.
For me the problem could be resolved by simply putting a dotnet restore task in front of the dotnet build task.
In the dotnet restore task I could then specify my feed. With just the dotnet build task it tried to restore nugets with the NuGet.conf file and the local logins, which is more error prone.
It seems that NuGet setapikey encrypts the credentials using the currently-logged-on-user's private key. Therefore, only that user can use these encrypted credentials. If a different user (a service account for CI/CD etc.) tries, they get Key not valid for use in specified state.

Private NuGet gallery not publishing

I have set up a NuGet Gallery for use inside my company as per the lengthy instructions at http://docs.nuget.org/docs/contribute/setting-up-a-local-gallery. However I when I push a package to the server it doesn't seem to recognize it even though nuget.exe reports no errors
NuGet.exe push -source http://myserver/NuGet-services/FeedService.svc/ publish\mypackage.0.1.nupkg
Pushing MyPackage 0.1 to 'http://myserver/NuGet-services/FeedService.svc/'...
Pushing: 100%
The API key is set to what my user has listed on its profile page. I have turned up the logging in the service to DEBUG but nothing at all is printed to the log. I have checked that the service has the ability to write to its data directory and to the database. The packages table in the database is empty as is the directory to which the packages look like they should be published (App_Data/Packages). If anybody has a suggestion short of attaching a debugger to this thing I would be most interested in your help.
You're pushing to the wrong url. You don't push to the feedservice.svc. The source should be the root (so http://myserver/NuGet-services/ in your case).