Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bjornbouetsmith/5b258ad1870daa8af60fd5d26ab2f909 to your computer and use it in GitHub Desktop.
Save bjornbouetsmith/5b258ad1870daa8af60fd5d26ab2f909 to your computer and use it in GitHub Desktop.
Fix nuget restore failing in Azure DevOps 2019
You can end up in a situation where Azure DevOps for one pipeline refuses to restore packages
and for another that references same packages it just works.
I am guessing there is a bug in Microsofts code somewhere.
This can me remedied by adding a default nuget.config to the roaming app data directory for the user that is running the build agents.
i.e. I have an agent running with the username tfsbuildagent
I have created a nuget.config in
C:\Users\tfsbuildagent\AppData\Roaming\NuGet
In the nuget file you just add the package sources for your Azure DevOps nuget package repository.
i.e.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="VSTS - Release" value="http://build.root.dom/ROOT/_packaging/root-release/nuget/v3/index.json" protocolVersion="3" />
<add key="VSTS - 3rdparty" value="http://build.root.dom/ROOT/_packaging/3rdparty/nuget/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
When that has been done and server restarted, it might just work, but to be 100% sure, add the user running the build agent to an
Azure DevOps group that have Contribute access to the feeds in the server.
Otherwise you might end up with an error similar to:
C:\Program Files\dotnet\sdk\2.2.104\NuGet.targets(114,5): error : Response status code does not indicate success: 403 (Forbidden - User 'ROOT\tfsbuildagent' lacks permission to complete this action. You need to have 'ReadPackages'.
Adding the tfsbuildagent user to a group in Azure Devops with Contribute access on the feed, enabled the restore to work again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment