microsoft/aspire · error · InvalidOperationException
Bundle layout not found. Cannot perform NuGet restore in…
Error message
Bundle layout not found. Cannot perform NuGet restore in bundle mode.
What it means
BundleNuGetService.RestorePackagesAsync restores integration packages through the extracted bundle. It obtains a layout either from the bundle service lease or via ILayoutDiscovery.DiscoverLayout(); when both yield null, it throws this InvalidOperationException because restore in bundle mode requires a valid bundle layout directory.
Solutions
- Reinstall the Aspire CLI bundle to ensure a valid, extractable layout
- Verify the extraction/install directories exist and are writable by the current user
- Run the CLI normally once so the bundle gets extracted before restore is invoked
- Check environment/paths that layout discovery relies on; update the CLI if the issue persists
Defensive patterns
Strategy: fallback
Validate before calling
// Precheck that a bundle layout is discoverable before restore
var layout = layoutDiscovery.DiscoverLayout();
if (layout is null)
{
// reinstall/extract bundle before invoking restore
} Try / catch
try
{
await service.RestorePackagesAsync(packages, workingDir);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Bundle layout not found"))
{
// repair bundle installation, then retry restore
} Prevention
- Ensure the CLI bundle is fully installed and extracted before automated restores
- Grant write access to the extraction/cache directories used by the CLI
- Don't run restore flows from stripped/portable copies of the CLI lacking a layout
- Reinstall after OS-level cleanups that remove the bundle cache
When it happens
Trigger: Calling RestorePackagesAsync (used by AppHost integration probes / manifest restore flows) when EnsureExtractedAndAcquireLayoutAsync returns no lease and DiscoverLayout() finds no layout — i.e. no valid extracted bundle exists.
Common situations: CLI installed without a complete bundle; extraction directory wiped or unwritable; DiscoverLayout unable to locate the install layout due to a moved/deleted install path or environment mismatch.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- aspire-managed not found in layout.
- aspire-managed not found in layout.
- Bundle layout not found. Cannot perform NuGet search in…
- Failed to restore packages for project
- Manifest creation failed
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/5856d84454357312.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Cli/NuGet/BundleNuGetService.cs:87
public async Task<string> RestorePackagesAsync(
IEnumerable<(string Id, string Version)> packages,
string workingDirectory,
string targetFramework = "net10.0",
string? runtimeIdentifier = null,
IEnumerable<string>? sources = null,
string? nugetConfigPath = null,
CancellationToken ct = default)
{
ArgumentException.ThrowIfNullOrWhiteSpace(workingDirectory);
using var layoutLease = _bundleService is null
? null
: await _bundleService.EnsureExtractedAndAcquireLayoutAsync("cli", "nuget-restore", ct).ConfigureAwait(false);
var layout = layoutLease?.Layout ?? _layoutDiscovery.DiscoverLayout();
if (layout is null)
{
throw new InvalidOperationException("Bundle layout not found. Cannot perform NuGet restore in bundle mode.");
}
var managedPath = layout.GetManagedPath();
if (managedPath is null || !File.Exists(managedPath))
{
throw new InvalidOperationException("aspire-managed not found in layout.");
}
var packageList = packages.ToList();
if (packageList.Count == 0)
{
throw new ArgumentException("At least one package is required", nameof(packages));
}
// Compute a hash for the package set to create a unique restore location.
var packageHash = ComputePackageHash(packageList, targetFramework, runtimeIdentifier, managedPath, sources);
var restoreCacheDirectory = GetPackageRestoreCacheDirectory(workingDirectory);
var restoreDir = Path.Combine(restoreCacheDirectory, packageHash);View on GitHub (pinned to 25830f84bd)