Skip to content

Instantly share code, notes, and snippets.

@AizazZaidee
Last active September 18, 2023 10:21
Show Gist options
  • Save AizazZaidee/49ce9cf54079a5a1dd39d5efc5cf79f0 to your computer and use it in GitHub Desktop.
Save AizazZaidee/49ce9cf54079a5a1dd39d5efc5cf79f0 to your computer and use it in GitHub Desktop.
Push .nuget packages to the Azure Artifacts Feed
#Install Azure CLI
Install MSI Installer from Microsoft, see the following URL
https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?tabs=azure-cli#install-or-update
#Download the Nuget.exe
Go to https://www.nuget.org/downloads and download the latest "exe" under "Windows x86 Commandline" column.
#Download Microsoft Azure Artifacts Credential Provider
Go to https://github.com/microsoft/artifacts-credprovider and scroll down to the section "Manual installation on Windows" and get the latest
"Microsoft.NuGet.CredentialProvider.zip". Please make sure to get the compiled, if "Net6" is in the name then it is not compiled.
#Move the Nuget.exe into the same folder where you installed the Microsoft Azure Artifacts Credential Provider
#Generate Personal Access Token (PAT) using the Microsoft Credential Provider
I am using "Terminal" App from the Windows store, because I can also run Linux commands on it. So, the command format is as per the Terminal
App. https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701
.\CredentialProvider.Microsoft.exe -U https://Your-URL/_packaging/third-party/nuget/v3/index.json -C
This command will generate following information, keep it safe somewhere, you'll need it later.
[Information] [CredentialProvider]Username:
[Information] [CredentialProvider]Password:
#Add the package sources to the donwnloaded Nuget.exe
```
.\nuget.exe sources add -Name "THE NAME OF YOUR FEED" -Source https://YOURE-FEED-URL/nuget/v3/index.json -username "THE GENERATED USERNAME" -password "THE GENERATED PAT TOKEN"
```
The above command will add the feed name along with the necessary information into your "C:\Users\YourUserName\AppData\Roaming\NuGet\NuGet.config" file.
#Push the package to the Nuget feed
Now you can use the following command to push the acutal nuget package into the configured feed.
.\nuget.exe push -Source "third-party" -ApiKey fakeKey C:\Users\YourUserName\Desktop\package.name.6.0.0.nupkg
Now you can consume this feed in your Visual Studio or anyother IDE of your choice.
You can push multiple pakcages from a folder using this command
.\nuget.exe push -Source "third-party" -ApiKey fakeKey C:\Users\xxx\Nuget_Packages\**\*.nupkg
Please use back slash or front depending on your OS. The "\**\" just means to do a recursive search in the path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment