ARTIFACTORY: How to Use Artifactory as a Source for NuGet Restore

ARTIFACTORY: How to Use Artifactory as a Source for NuGet Restore

Products
Frog_Artifactory
Content Type
Administration_Platform
AuthorFullName__c
Tatarao Vana, Akshatha P
articleNumber
000005270
FirstPublishedDate
2022-05-17T10:39:52Z
lastModifiedDate
2025-07-17
VersionNumber
6
Introduction 

According to official Microsoft documentation, if we execute the Nuget restore command inside a project, it tries to install all the package dependencies according to the references in your project file(.csproj) or your packages.config file. First, it installs the direct dependencies, then installs the dependencies of those packages throughout the entire dependency graph.


Nuget restore using Artifactory:
If a package isn't already installed, NuGet first attempts to retrieve it from the cache. Suppose the package is not available in the cache, NuGet attempts to download the package from all enabled sources in the list. We need to configure Artifactory here to resolve packages based on the NuGet client's requirements. Here is the sample client configuration.

Configure the NuGet client to resolve packages from Artifactory
$ cat ~/.config/NuGet/NuGet.Config
<?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="Artifactory" value="https://jpd.local/artifactory/api/nuget/v3/test-nuget/index.json" />
    <add key="ArtifactoryV2" value="https://jpd.local/artifactory/api/nuget/test-nuget" />
  </packageSources>
  <packageSourceCredentials>
    <Artifactory>
        <add key="Username" value="testadmin" />
        <add key="Password" value="xxxxxx" />
      </Artifactory>
    <ArtifactoryV2>
      <add key="Username" value="testadmin" />
      <add key="Password" value="xxxxxx" />
    </ArtifactoryV2>
  </packageSourceCredentials>
  <apikeys>
    <add key="https://jpd.local/artifactory/api/nuget/v3/test-nuget/index.json" value="xxxxxx" />
    <add key="xxxxxx" />
  </apikeys>
</configuration>

NuGet restore steps:
1. Clone a sample
    repository(https://github.com/NuGet/Samples/tree/main/Satellite-Packages) or create a NuGet Project.
2. Configure the NuGet client to resolve packages using Artifactory.
3. Perform NuGet restore inside the Project.

$ nuget restore SatellitePackageSample.sln
Restoring NuGet package ClassLibrary.1.0.0.
Adding package 'ClassLibrary.1.0.0' to folder '/Users/Samples/Satellite-Packages/packages'
Added package 'ClassLibrary.1.0.0' to folder '/Users/Samples/Satellite-Packages/packages'
  GET https://api.nuget.org/v3/vulnerabilities/index.json
  OK https://api.nuget.org/v3/vulnerabilities/index.json 296ms
  GET https://api.nuget.org/v3-vulnerabilities/2025.06.28.11.49.20/vulnerability.base.json
  GET https://api.nuget.org/v3-vulnerabilities/2025.06.28.11.49.20/2025.07.06.05.49.48/vulnerability.update.json
  OK https://api.nuget.org/v3-vulnerabilities/2025.06.28.11.49.20/vulnerability.base.json 304ms
  OK https://api.nuget.org/v3-vulnerabilities/2025.06.28.11.49.20/2025.07.06.05.49.48/vulnerability.update.json 566ms
NuGet Config files used:
    /Users/Samples/Satellite-Packages/.nuget/NuGet.Config
    /Users/.config/NuGet/NuGet.Config

Feeds used:
    /Users/.nuget/packages/
    https://api.nuget.org/v3/index.json
    https://jpd.local/artifactory/api/nuget/v3/test-nuget/index.json
    https://jpd.local/artifactory/api/nuget/test-nuget

Installed:
    1 package(s) to packages.config projects

4. Verify the Artifactory logs.
2025-07-09T19:29:18.796Z [jfrt ] [INFO ] [12c530317d1320e2] [o.a.r.HttpRepo:506            ] [http-nio-8081-exec-9] - test-nuget-remote downloaded  https://api.nuget.org/v3-flatcontainer/classlibrary/1.0.0/classlibrary.1.0.0.nupkg 13.44 KB at 765.35 KB/sec
2025-07-09T19:29:18.995Z [jfrt ] [INFO ] [12c530317d1320e2] [o.j.r.n.NuGetWorkContext:79   ] [d1320e2|art-exec-327] - Indexing NuGet metadata for repo 'test-nuget-remote-cache' on path 'classlibrary.1.0.0.nupkg'
2025-07-09T19:29:19.011Z [jfrt ] [INFO ] [12c530317d1320e2] [o.j.r.n.NuGetWorkContext:106  ] [d1320e2|art-exec-327] - Finished writing Nuget metadata for repo test-nuget-remote-cache on path 'classlibrary.1.0.0.nupkg' took 210 ms