Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.
If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!
Download/ upload a NuGet package using cmd with ProGet Key or Username/ password
-
Re: Download a NuGet package using cmd
Q1: How can I pass the API key or username and password using the example provided of my old forum?
Q2: How can I upload a NuGet package to a ProGet feed using similar API?
Can you provide me with PowerShell script for that as in the referenced in my old forum?
-
If you plan to use the NuGet API, it's best to familiarize yourself with how it works. We do not document this API nor provide examples, we simply implement Microsoft's API. Here area few links that may be helpful:
- https://learn.microsoft.com/en-us/nuget/api/overview
- https://learn.microsoft.com/en-us/nuget/api/package-publish-resource
When Basic authentication is required, you can use
api
/{your-key}
for username/password. You can learn more about API keys in ProGet here:As an alternative, you may find ProGet's Common Package API to be easier to use; we also document it and have several examples:
Best,
Alana
-
The Following is the reply from Steve https://forums.inedo.com/topic/3956/download-a-nuget-package-using-cmd/2?_=1710614207806
I see a few issues here...
First, the URL you're using is not correct; the easiest way to to find the url by clicking the "download package link" in the ProGet UI. It will look like this: /nuget/your-feed-name/package/your-package-name/your-version-number
Second, you're downloading a file - so you want to use a powershell command like this:
$url = "https://myprogetserver/feeds/mynuggets/package/mypackage/1.0.0"
$destination = "c:\mypackages\mypackage-1.0.0.zip"
Invoke-WebRequest -Uri $url -OutFile $destination
Best,
SteveI tried api/{your-key} but it did not work.
$url = "https://myprogetserver/feeds/mynuggets/package/mypackage/1.0.0/mykey"
$destination = "c:\mypackages\mypackage-1.0.0.zip"
Invoke-WebRequest -Uri $url -OutFile $destinationI would like to download the package as mypackage.zip file. I do not need to install it.
Is this correct? "https://myprogetserver/feeds/mynuggets/package/mypackage/1.0.0/mykey"Thanks,
Hashim
-
If you need to authenticate to the feed, you need to pass an API key using Basic authentication., with
api
as the username and your key as the password.Here is one way to do this in PowerShell.
$user = 'api' $pass = 'abcdefg12345' $pair = "$($user):$($pass)" $encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair)) $basicAuthValue = "Basic $encodedCreds" $Headers = @{ Authorization = $basicAuthValue } $url = "https://myprogetserver/feeds/mynuggets/package/mypackage/1.0.0" $destination = "c:\mypackages\mypackage-1.0.0.zip" Invoke-WebRequest -Uri $url -OutFile $destination -Headers $Headers
I would recommend first getting your scripts to work without authentication, then add it in later.
Cheers,
Alana
-
This post is deleted!
-
Hi Alana,
I found the issue of the url provided from the former forum. It should be "nuget" instead of "feeds", as follows:
$url = "https://myprogetserver/nuget/mynuggets/package/mypackage/1.0.0"The complete PowerShell is as follows:
$user = 'api' $pass = 'abcdefg12345' $pair = "$($user):$($pass)" $encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair)) $basicAuthValue = "Basic $encodedCreds" $Headers = @{ Authorization = $basicAuthValue } $url = "https://myprogetserver/nuget/mynuggets/package/mypackage/1.0.0" $destination = "c:\mypackages\mypackage-1.0.0.zip" Invoke-WebRequest -Uri $url -OutFile $destination -Headers $Headers
Thanks,
Hashim
-
@hashim-abu-gellban_3562 nice find, correct that was a typo :)