NuGetFetch 0.7.0

dotnet add package NuGetFetch --version 0.7.0
                    
NuGet\Install-Package NuGetFetch -Version 0.7.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NuGetFetch" Version="0.7.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NuGetFetch" Version="0.7.0" />
                    
Directory.Packages.props
<PackageReference Include="NuGetFetch" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NuGetFetch --version 0.7.0
                    
#r "nuget: NuGetFetch, 0.7.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NuGetFetch@0.7.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NuGetFetch&version=0.7.0
                    
Install as a Cake Addin
#tool nuget:?package=NuGetFetch&version=0.7.0
                    
Install as a Cake Tool

NuGetFetch

NuGet

A lightweight NuGet client library for downloading and extracting NuGet packages. Designed for AOT compatibility with zero HttpClient ownership — bring your own.

dotnet add package NuGetFetch

Features

  • Stream-based — All JSON from streams, no string buffering
  • AOT compatible — STJ source generation, no reflection
  • No HttpClient — Accepts HttpClient from the caller
  • Two-tier caching — Reads ~/.nuget/packages, writes app cache
  • Source resolution — Parses nuget.config files (with credentials)
  • TFM resolution — Selects highest-priority target framework
  • Version resolution — Full ascending list, latest, wildcard patterns, prerelease
  • Search — Query nuget.org with prefix filtering

Usage

using NuGetFetch;

HttpClient httpClient = new();
NuGetClient client = new(httpClient);

// Get latest version
string? version = await client.GetLatestVersionAsync("Newtonsoft.Json");

// List every published version, ascending (oldest first, newest last)
IReadOnlyList<string> versions = await client.GetVersionsAsync("Newtonsoft.Json");
string oldest = versions[0];
string newest = versions[^1];

// Download and extract
using Stream nupkg = await client.DownloadAsync("Newtonsoft.Json", version!);
string extractPath = Path.Combine(Path.GetTempPath(), "Newtonsoft.Json");
await PackageExtractor.ExtractAsync(nupkg, extractPath);

// Find the best TFM
string? tfmPath = TfmResolver.ResolvePackagePath(extractPath);
SearchService search = new(httpClient);

// Search for packages
IReadOnlyList<SearchResult> results = await search.SearchAsync("json serializer");

// Prefix search
IReadOnlyList<SearchResult> results = await search.SearchByPrefixAsync("Newtonsoft");

Caching

Two-tier cache: reads from ~/.nuget/packages and writes to an app-specific cache.

PackageCache cache = new("my-app");

// Check cache first
string? cached = cache.TryGet("Newtonsoft.Json", "13.0.3");

if (cached is null)
{
    // Download, extract, then cache
    using Stream nupkg = await client.DownloadAsync("Newtonsoft.Json", "13.0.3");
    string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
    await PackageExtractor.ExtractAsync(nupkg, tempPath);
    cached = cache.Cache("Newtonsoft.Json", "13.0.3", tempPath);
}

Source Resolution

// Auto-discover from nuget.config files
IReadOnlyList<PackageSource> sources = SourceResolver.ResolveSources();

// Or specify explicitly
IReadOnlyList<PackageSource> sources = SourceResolver.ResolveSources(
    explicitSource: "https://my-feed.example.com/v3/index.json");

Version Patterns

// Resolve wildcard patterns
string? version = await client.ResolveVersionPatternAsync("Newtonsoft.Json", "13.*");

// Parse "Package@Version" specs
PackageIdentity? parsed = PackageExtractor.ParsePackageReference("Newtonsoft.Json@13.0.3");

Tool wrapper packages

.NET tools published as runtime-specific (e.g. NativeAOT) executables ship a thin wrapper package whose only payload is a DotnetToolSettings.xml manifest pointing at per-RID packages (<id>.win-x64, <id>.osx-arm64, <id>.any, …). To read managed metadata, redirect to the portable any payload:

string extractPath = PackageExtractor.Extract(nupkgPath, destination);

// Returns "mytool.any" when the package is a wrapper with no managed libraries; else null.
string? payloadId = PackageExtractor.TryGetToolWrapperRedirect(extractPath);
if (payloadId is not null)
{
    // Fetch + extract payloadId at the same version, then inspect that.
}

API Overview

Class Kind Purpose
NuGetClient Instance Versions, download
SearchService Instance Search and prefix search
PackageCache Instance Two-tier package cache
ResponseCache Instance Disk cache with TTL
PackageExtractor Static Extract .nupkg, parse
SourceResolver Static Parse nuget.config files
TfmResolver Static Select best TFM
NuGetApi Static Stream JSON deserialization

Design

Follows the distroessed library patterns:

  • POCOs — Records with primary constructors for all data models
  • STJ source generationNuGetJsonContext for AOT-safe JSON
  • Stream-based helpersNuGetApi for stream deserialization
  • No HttpClient ownership — Library never creates an HttpClient

Dependencies

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on NuGetFetch:

Repository Stars
richlander/dotnet-inspect
Tool to inspect .NET assets, like docker inspect and kubectl describe.
Version Downloads Last Updated
0.7.0 100 6/29/2026
0.6.2 6,639 6/17/2026
0.6.1 5,930 3/18/2026
0.6.0 125 3/18/2026
0.5.0 238 3/17/2026
0.4.0 131 3/17/2026
0.3.0 132 3/17/2026
0.2.0 191 3/17/2026
0.1.0 160 3/16/2026