Intro
I decided to write this post for anyone struggling to setup and use private nuget feed from Azure DevOps, because in my opinion the microsoft documentation is little bit confusing in this case.
Prerequisities
- nuget – https://www.nuget.org/downloads
Creating nuget feed
Creating new feed is straigt forward. Open Azure DevOps, and select Artifacts in side menu. Then click on + New feed
, give the feed new name and click Create
.
Missing artefacts?
If you can’t see Artifacts menu item then it’s probably disabled in Project settings
. To enable it, open Project settings
, also from left sidebar menu, select Overview
and in Azure DevOps services
section, enable Artifacts switch.
Uploading packages to your feed
Great, now we have the feed, but there are no packages, let’s add them. Considering you are still on artifacts page, select your feed from dropdown menu and then click Connect to feed
button.
Next page differes little bit, depending on your Azure DevOps version, but in either case we need to get our Package source url.
Select nuget.exe from side menu and copy Package Source Url(it ends with .../nuget/v3/index.json
).
Latest versions of Azure DevOps
First add your feed to nuget sources:
1 |
nuget sources add -name 'YourFeedName' -Source 'https://pkgs.dev.azure.com/YourOrg/YourProject/_packaging/YourFeedName/nuget/v3/index.json' |
Install Azure Artifacts credential provider, follow instructions on github or for windows just run from powershell:
1 |
iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) }" |
You can then check that nuget \plugins
directory contains \netcore
folder using ls "$env:UserProfile\.nuget\plugins"
.
Finally go to a directory where your .nupkg file is and run following snippet:
1 |
nuget push -source YourFeedName .\Test.1.0.0.nupkg |
Microsoft Sign in window should automatically pop up.
When you enter your credentials, you should see message Your package was pushed.
.
Older versions(on premise) Azure DevOps
Edit following snippet with your package source url, credentials and run it:
1 |
nuget sources add -name 'YourFeedName' -Source 'https://yourtfsurl.com/tfs/YourProject/_packaging/YourFeedName/nuget/v3/index.json' -username '[email protected]' -password '***' |
Previous code will add your feed to nuget sources. Next we need Personal Access Token(PAT). In Azure DevOps, open user settings in top right corner, click on Security
and on next page select Personal Access Tokens.
Click on + New Token
, give it name and expiration, then on bottom click Show all scopes
and select Read & write
permission under Packaging.
Click Create
to generate new PAT. Store it securely, we will need it in next step.
Now we need to assing the PAT/Api key to our nuget feed:
1 |
nuget setApiKey '***Your PAT***' -Source 'YourFeedName' |
You can verify all nuget settings inside %APPDATA%\NuGet\nuget.config
, you should see similar configuraton file(note that all sensitive information is encrypted):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?xml version="1.0" encoding="utf-8"?> <configuration> <config> <add key="defaultPushSource" value="https://api.nuget.org/v3/index.json" /> </config> <packageSources> <add key="FileMove" value="https://yourtfsurl.com/tfs/YourProject/_packaging/YourFeedName/nuget/v3/index.json" /> </packageSources> <apikeys> <add key="https://yourtfsurl.com/tfs/YourProject/_packaging/YourFeedName/nuget/v3/index.json" value="AA2CkbanNJbUeSbYO7x6gy8w... ...AAAAACAAAAAAAQZgAAD95nH16=" /> </apikeys> <packageSourceCredentials> <FileMove> <add key="Password" value="AAAAEAACAAAACHI1RkJo5Tx40EiCuBadb7UK... ...EXZxNnk6wAAAAAOgAAAAAIAACAAAABYp06oqGoDm5Z1dIrdl0uC9==" /> </FileMove> </packageSourceCredentials> </configuration> |
Finally lets push our nuget package(Test.1.0.0.nupkg):
1 |
nuget push -source YourFeedName .\Test.1.0.0.nupkg |
After that, you should see Test.1.0.0.nupkg
package appear in Azure DevOps.
Consuming your packages from Visual Studio
In Visual Studio right click project Dependencies and select Manage NuGetPackages...
.
In next window select your package source in top right corner(or select All
). Finally you sould see your package in browse tab.
Conclusion
That’s it, if you followed this manual you should be able to use your nuget packages from Azure DevOps feed.