microsoft/aspire · error · NuGetPackageCacheException
Failed to search for packages. Exit code
Error message
Failed to search for packages. Exit code: {0}. What it means
After running aspire-managed nuget search, BundleNuGetPackageCache checks the process exit code. A non-zero exit code means the search command failed (e.g. network/feed errors), so it logs stderr/stdout and throws NuGetPackageCacheException with a message embedding the exit code.
Solutions
- Check CLI debug logs for the logged stderr/stdout of the failed search to see the underlying NuGet error
- Verify network access to the NuGet source(s) and configure the proxy correctly
- Fix or remove the nuget.config in the working directory (or pass a valid --nuget-config)
- Ensure NuGet credential providers are installed for authenticated feeds and retry
Defensive patterns
Strategy: retry
Validate before calling
// Validate feed reachability before search curl -fsSL https://api.nuget.org/v3/index.json > /dev/null || echo "NuGet source unreachable"
Try / catch
try
{
await cache.SearchPackagesAsync(...);
}
catch (NuGetPackageCacheException ex) when (ex.Message.StartsWith("Failed to search for packages"))
{
// inspect CLI debug logs for stderr; fix feed/proxy/credentials; retry
} Prevention
- Configure proxy and corporate firewall rules for NuGet endpoints in advance
- Install NuGet credential providers for any authenticated feeds
- Validate nuget.config files in project directories before running package commands
- Use --verbose/debug logging when debugging feed issues
When it happens
Trigger: Any `packages` search or version query where the aspire-managed `nuget search` helper process exits non-zero — unreachable NuGet source, bad nuget.config, auth failure on a private feed, or invalid query arguments.
Common situations: Corporate proxy blocking nuget.org; private Azure DevOps feed requiring credentials with no configured credential provider; malformed nuget.config in the working directory or passed via --nuget-config; offline machine.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- Package restore failed
- Failed to retrieve template packages via cache.
- No integration packages were found. Please check your…
- No template versions were found. Please check your internet…
- A SearchIndexClient could not be configured. Ensure valid…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/0ea51323964ea33c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Cli/NuGet/BundleNuGetPackageCache.cs:215
environmentVariables: environmentVariables,
// A package search against a slow/unresponsive NuGet source can hang. LayoutProcessRunner uses
// this to bind the helper to the CLI's Windows kill-on-close job (and, on non-Windows, to
// instead arm the cooperative parent-liveness watchdog) so a hard-killed CLI cannot leak it.
killOnParentExit: true,
ct: cancellationToken).ConfigureAwait(false);
// Log stderr output (verbose info from NuGetHelper)
if (!string.IsNullOrWhiteSpace(error))
{
_logger.LogDebug("NuGetHelper stderr: {Error}", error);
}
if (exitCode != 0)
{
_logger.LogError("NuGet search failed with exit code {ExitCode}", exitCode);
_logger.LogError("NuGet search stderr: {Error}", error);
_logger.LogError("NuGet search stdout: {Output}", output);
throw new NuGetPackageCacheException(string.Format(CultureInfo.CurrentCulture, ErrorStrings.FailedToSearchForPackages, exitCode));
}
_logger.LogDebug("NuGet search returned {Length} bytes", output?.Length ?? 0);
try
{
if (string.IsNullOrEmpty(output))
{
_logger.LogWarning("NuGet search returned empty output");
return [];
}
// The aspire-managed helper writes the search result as JSON to stdout, but a NuGet credential
// provider can write diagnostics before or after that payload. Extract exactly one complete root object
// with the expected bundle-search shape so provider diagnostics cannot be deserialized as the result.
// See https://github.com/microsoft/aspire/issues/19339.
var result = JsonSerializer.Deserialize(PackageUpdateHelpers.ExtractJsonPayload(output, IsBundleSearchPayload), BundleSearchJsonContext.Default.BundleSearchResult);
if (result?.Packages is null)View on GitHub (pinned to 25830f84bd)