{"record":{"id":"5856d84454357312","repo":"microsoft/aspire","slug":"bundle-layout-not-found-cannot-perform-nuget-restore-in","errorCode":null,"errorMessage":"Bundle layout not found. Cannot perform NuGet restore in bundle mode.","messagePattern":"Bundle layout not found\\. Cannot perform NuGet restore in bundle mode\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/NuGet/BundleNuGetService.cs","lineNumber":87,"sourceCode":"\n    public async Task<string> RestorePackagesAsync(\n        IEnumerable<(string Id, string Version)> packages,\n        string workingDirectory,\n        string targetFramework = \"net10.0\",\n        string? runtimeIdentifier = null,\n        IEnumerable<string>? sources = null,\n        string? nugetConfigPath = null,\n        CancellationToken ct = default)\n    {\n        ArgumentException.ThrowIfNullOrWhiteSpace(workingDirectory);\n\n        using var layoutLease = _bundleService is null\n            ? null\n            : await _bundleService.EnsureExtractedAndAcquireLayoutAsync(\"cli\", \"nuget-restore\", ct).ConfigureAwait(false);\n        var layout = layoutLease?.Layout ?? _layoutDiscovery.DiscoverLayout();\n        if (layout is null)\n        {\n            throw new InvalidOperationException(\"Bundle layout not found. Cannot perform NuGet restore in bundle mode.\");\n        }\n\n        var managedPath = layout.GetManagedPath();\n        if (managedPath is null || !File.Exists(managedPath))\n        {\n            throw new InvalidOperationException(\"aspire-managed not found in layout.\");\n        }\n\n        var packageList = packages.ToList();\n        if (packageList.Count == 0)\n        {\n            throw new ArgumentException(\"At least one package is required\", nameof(packages));\n        }\n\n        // Compute a hash for the package set to create a unique restore location.\n        var packageHash = ComputePackageHash(packageList, targetFramework, runtimeIdentifier, managedPath, sources);\n        var restoreCacheDirectory = GetPackageRestoreCacheDirectory(workingDirectory);\n        var restoreDir = Path.Combine(restoreCacheDirectory, packageHash);","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/NuGet/BundleNuGetService.cs#L69-L105","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Precheck that a bundle layout is discoverable before restore\nvar layout = layoutDiscovery.DiscoverLayout();\nif (layout is null)\n{\n    // reinstall/extract bundle before invoking restore\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    await service.RestorePackagesAsync(packages, workingDir);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Bundle layout not found\"))\n{\n    // repair bundle installation, then retry restore\n}","preventionTips":["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"],"tags":["nuget","bundle","restore","cli"],"backgroundTag":"resource-not-found","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}