How to Troubleshoot NuGet issues

Summary

Comparing correct NuGet REST API calls can show where the problem lies.

Affected Versions

4.0.2 – Latest

Description

When troubleshooting NuGet errors it is best to compare what is supposed to happen against what is currently happening. You can eliminate a great deal of noise by simulating each step the client takes, and examining what HTTP return code is sent by Artifactory.

In general, these return codes indicate where to look next:
403 and 401 – Authentication issue, examine authorization settings
404 – Resource not found, check repository for resource
400 – Incorrect request, use curl to get reason phrase
50X – Server problem, examine artifactory.log

Resolution

Using your Web Browser
Many NuGet projects can only be built on Windows hosts, which means that standard troubleshooting tools like libcurl are not available or have reduced functionality. 

Modern web browsers can be used to pull NuGet metadata if supplied with the correct URL. Simply go to the Artifactory URL, and after the “/artifactory” add the information from the request log to perform a GET action similar to the NuGet client.

This will display the correct XML metadata in the tab for further troubleshooting.

nuget list
Running a “nuget list” command causes the client to pull most of the NuGet metadata from Artifactory.

The client first gets an XML page of the proper “packages” API formatting:
20180530043930|53|REQUEST|64.71.2.36|anonymous|GET|/api/nuget/nuget|HTTP/1.0|200|0

It then gets the metadata formatting of the search command:
20180530043930|3|REQUEST|64.71.2.36|anonymous|GET|/api/nuget/nuget/$metadata|HTTP/1.0|200|0

Finally, it will then pull an XML page listing all available packages:
20180530043933|691|REQUEST|64.71.2.36|anonymous|GET|/api/nuget/nuget/Search()|HTTP/1.0|200|0

nuget install bang.test.bench
Running a “nuget install” command results in the client searching for the package in two different ways, depending on the NuGet client:

20180530044235|351|REQUEST|64.71.2.36|anonymous|GET|/api/nuget/nuget/FindPackagesById()|HTTP/1.0|200|0
— or —
20180516133017|727|REQUEST|10.6.16.165|admin|GET|/api/nuget/nuget-remote/Packages(Id=’bang.test.bench’,Version='0.1.6.0')|HTTP/1.1|200|0

This XML metadata contains the download link for the package, which the client then uses:

20180530044237|1523|REQUEST|64.71.2.36|anonymous|GET|/api/nuget/nuget/Download/bang.test.bench/0.1.6.0|HTTP/1.0|200|4359

The .nupkg file is pulled via the above URL, and can be manually downloaded via a web browser to test this.

Nuget push bang.test.bench.nupkg
A “nuget push” command runs a PUT with the .nupkg as the payload:
20180530044608|99|REQUEST|64.71.2.36|admin|PUT|/api/nuget/nuget/|HTTP/1.0|201|4587

The metadata contained in the .nupkg file is read by Artifactory during the Indexing phase, which updates the metadata for the repository.