Github Package: Key not valid for use in specified state - nuget-package

I am unable to use the package published by another user.
Process:
Added the new package name and source by updating the nuget.config
Added the package source username and password(APIKey)
Tried added the NuGet package generated by admin account though NuGet package manager but not able to see it.
Giving error:
Feeds used:
https://api.nuget.org/v3/index.json
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
https://nuget.pkg.github.com/account/index.json
NuGet package restore finished.
Key not valid for use in specified state.
Any Ideas?

Related

How to download NPM package published to GitHub packages registry as a zip?

I am using GitHub packages to publish my private NPM packages. I need to download the published package of specific version for carrying out automation work. How can I download the package as a zip bundle using GitHub REST API or equivalent? Additionally, since it is a private package, it needs to be authenticated.
I know that equivalent functionality exists but it works for GitHub releases and assets. I could not find anything yet for GitHub packages!
After a few days of intermittent research regarding this question, here is what I have found. There seem to be two methods of retrieving and/or consuming privately published NPM packages from the GitHub Package Registry. And neither of them is an exact match to your desired method, so, here goes...
OPTION 1.
You can consume the npm package directly within your application provided you have a locally configured .nprmc file on your machine in your user directory (check first #~/.npmrc),
AND
you have created a GitHub personal access token with the following scopes.
repo: full (this is how you will be authenticated.)
workflow
write: packages
adminOrg: read
user: email
NOTE: You may not require all of these, but these are the permissions I used and had no issues. Once you generate the token, create or add it to your .npmrc file like so, replacing TOKEN with the actual token value.
//npm.pkg.github.com/:_authToken=TOKEN
Be sure you additionally add the following snippet into the project or container itself within another .npmrc file in the root directory of the codebase.
#YOUR_GITHUB_USERNAME:registry=https://npm.pkg.github.com
OPTION 2:
You can connect your package to a private GitHub repository, which will allow you to access the tar.gz artifact for each version of your package and directly download it to your local machine from the web.
github.com > Your profile > Packages > Connect repository > Select and link.
REFERENCE: How to publish packages to the GitHub Package Registry

Install NuGet package from GitHub Package Registry

After a lot of trial and error I eventually got my NuGet package on the Github package registry with the following actions/commands:
Go to GitHub
Click your avatar (top-right) → Settings → Developer settings → Personal access tokens
Generate a token with following scopes: write:packages, read:packages, delete:packages
This will automatically check the repo scope for your OAuth token
Open cmd
Navigate to your project directory or the directory containing your NuGet package
Add a new nuget source
dotnet nuget add source --username [GithubUserName] --password [YourApiKey] --name github https://nuget.pkg.github.com/[UsernameOrOrganizationName]/index.json
Push the package to the github source
dotnet nuget push --source github bin\Release\MyAwesomePackage.1.0.0.nupkg
I can see my NuGet package on GitHub, so now I want to install it.
I created a new project → Manage NuGet packages → Settings
Add package source:
Name: whatever
Source: https://nuget.pkg.github.com/[UsernameOrOrganizationname]/index.json
Now I should be able to install my package. But when I select my source and browse for packages, a GitHub login window pops up. And even when I login with my user account credentials, I still can't access my packages (pushed to an organization Github). Now when I use the NuGet package manager for my custom package source I always get the following error in the Output Window:
[source-name] Failed to retrieve metadata from source 'https://nuget.pkg.github.com/[UsernameOrOrganizationname]/query?q=&skip=0&take=26&prerelease=true&semVerLevel=2.0.0'.
Response status code does not indicate success: 401 (Unauthorized).
The packages pushed to the GitHub registry should be public, and even with my user account I can't access them for installation. However they appear on my organization's GitHub page.
Also the other users shouldn't have to add my personal GitHub package source, but rather the package should appear in some global GitHub feed inside the package manager, not?
What am I doing wrong?
It appears that righg now it's not yet possible: https://github.community/t/download-from-github-package-registry-without-authentication/14407/39
First, make sure that your credential info is correct on the nuget.config file.
If you want to config this github package source for all the projects on your PC, you should config it on the global nuget.config file.
please add your content of the file into C:\Users\xxx(current user)\AppData\Roaming\NuGet\NuGet.Config.
restart VS Instance or restart PC to enable this new nuget.config file. It is designed by that.

How can I debug what targets a given NuGet package?

I'm trying to install Twilio Voice for Xamarin, and when I try to add it to my app, I get this error:
Attempting to gather dependency information for package 'Twilio.Voice.Xamarin.2.0.0-beta4-1' with respect to project 'voipphone', targeting 'Xamarin.iOS,Version=v1.0'
GET https://api.nuget.org/v3/registration1-gz/twilio.voice.xamarin/index.json
OK https://api.nuget.org/v3/registration1-gz/twilio.voice.xamarin/index.json 169ms
Total number of results gathered : 5
Gathering dependency information took 705.89 ms
Summary of time taken to gather dependencies per source :
https://api.nuget.org/v3/index.json - 171.21 ms
Attempting to resolve dependencies for package 'Twilio.Voice.Xamarin.2.0.0-beta4-1' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'Twilio.Voice.Xamarin.2.0.0-beta4-1'
Resolved actions to install package 'Twilio.Voice.Xamarin.2.0.0-beta4-1'
Retrieving package 'Twilio.Voice.Xamarin 2.0.0-beta4-1' from 'nuget.org'.
Install failed. Rolling back...
Package 'Twilio.Voice.Xamarin.2.0.0-beta4-1' does not exist in project 'privatephone'
Package 'Twilio.Voice.Xamarin.2.0.0-beta4-1' does not exist in folder '/Users/Joe/Projects/voipapp/packages'
Executing nuget actions took 56.56 ms
Could not install package 'Twilio.Voice.Xamarin 2.0.0-beta4-1'. You are trying to
install this package into a project that targets 'Xamarin.iOS,Version=v1.0',
but the package does not contain any assembly references or content files that are compatible
with that framework. For more information, contact the package author.
Question
How can I manually download, inspect this NuGet package so I can see its intended use?
To download a Nuget Package, just go to this url: https://www.nuget.org/api/v2/package/Twilio.Voice.Xamarin/2.0.0-beta4-1
Once you download it, you can use something like 7zip to extract it and see its contents.
Looking inside it, it is designed for Xamarin.iOS and Android and I successfully installed it in my Xamarin.iOS app.

Azure build - [error]Unable to find version '' of package

Im trying to get a solution with Syncfusion to work.
But every time I try to deploy to Azure i get the following errors
##[error]Unable to find version '13.3.0.12' of package 'Syncfusion.AspNet.Mvc5'.
##[error]Unable to find version '13.3.0.12' of package 'Syncfusion.JavaScript'.
##[error]Unable to find version '13.3.0.12' of package 'Syncfusion.Web.Base45'.
##[error]Unable to find version '13.3.0.12' of package 'Syncfusion.Web.FileFormatsBase45'.
##[error]Unexpected exit code 1 returned from tool NuGet.exe
I tried creating a NuGet.config with the link to the syncfusion but dont work.
If i check the Packages folder i can see all the packages it says it cant find
Hope somone can help
Apparently you are using private NuGet feed, as these packages are not listed on the official NuGet feed, thus the error message.
Here is confirmation that these packages are not listed on the public NuGet feed:
http://www.nuget.org/packages?q=Syncfusion.AspNet.Mvc5
http://www.nuget.org/packages?q=Syncfusion.JavaScript
http://www.nuget.org/packages?q=Syncfusion.Web.Base45
http://www.nuget.org/packages?q=Syncfusion.Web.FileFormatsBase45
Which is also confirmed by the Syncfusion docs, which describe a custom feed for their packages: http://help.syncfusion.com/extension/syncfusion-nuget-packages/nuget-install-and-configuration
To enable restore of Syncfusion packages, check this SO question and its accepted answer on how can you include custom NuGet feeds to your Azure Web app deployment.

MSBuildTasks and NuGet - How can I restore MSBuild.Community.Tasks.dll?

I have a project which has a NuGet package called MSBuildTasks installed. It installs two files: MSBuild.Community.Tasks.targets and MSBuild.Community.Tasks.dll to the .build directory within the solution directory. This package reference has been added to the packages.config file in that project directory so that when I build the project (and with the NuGet package restore settings enabled) it will restore the package which is great because then I can distribute the source to other developers and build it on our build server without any missing files...
However, the problem is that when NuGet restores the package, it doesn't restore these two files to the expected location it was originally in when I first installed it with the Install-Package MSBuildTasks command, which was in to the $(SolutionDir)\.build directory. Instead, it has installed it to the $(SolutionDir)\packages\MSBuildTasks.1.4.0.78\tools directory, so now if I wish to include the MSBuild.Community.Tasks.targets file, I must reference this path absolutely in my .csproj or other .targets file. This presents a problem since the version number will undoubtedly change, requiring manual work to correct.
Is there some way that I can restore the MSBuildTasks .targets and .dll files to the original location of $(SolutionDir)\.build where it first installs to? The current behaviour of restoring in to the packages directory, while it makes sense for other packages, seems like a bug for this particular package since I will not be able to know the version number of the directory to include in my other .targets or .csproj files.
NuGet restore will only download files to the packages directory. It will not make any other modifications.
Looking at the MSBuildTasks NuGet package the files added to the $(SolutionDir)\.build are added by a PowerShell script. This PowerShell script will not be run when restoring the NuGet package.
You should add the $(SolutionDir)\.build to your source control repository.
With the newer versions 1.5+ the Nuget package doesn't install itself in the solution directory; this worked for me though:
<PropertyGroup>
<MSBuildCommunityTasksPath>$(USERPROFILE)\.nuget\packages\msbuildtasks\1.5.0.235\tools</MSBuildCommunityTasksPath>
</PropertyGroup>
It does involved adding the version, but if someone knows a way to remove having to update the version on the path when you update the package that would be awesome.

Resources