{"record":{"id":"634fc1d1263ec725","repo":"microsoft/aspire","slug":"package-restore-failed-error","errorCode":null,"errorMessage":"Package restore failed: {error}","messagePattern":"Package restore failed: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/NuGet/BundleNuGetService.cs","lineNumber":209,"sourceCode":"            environmentVariables: environmentVariables,\n            // A restore against a slow/unresponsive NuGet source can hang. LayoutProcessRunner uses this\n            // to bind the helper to the CLI's Windows kill-on-close job (and, on non-Windows, to instead\n            // arm the cooperative parent-liveness watchdog) so a hard-killed CLI cannot leak it.\n            killOnParentExit: true,\n            ct: ct);\n\n        // Log stderr at debug level for diagnostics\n        if (!string.IsNullOrWhiteSpace(error))\n        {\n            _logger.LogDebug(\"NuGetHelper restore stderr: {Error}\", error);\n        }\n\n        if (exitCode != 0)\n        {\n            _logger.LogError(\"Package restore failed with exit code {ExitCode}\", exitCode);\n            _logger.LogError(\"Package restore stderr: {Error}\", error);\n            _logger.LogError(\"Package restore stdout: {Output}\", output);\n            throw new InvalidOperationException($\"Package restore failed: {error}\");\n        }\n\n        // Step 2: Create package probe manifest\n        // Prepend \"nuget\" subcommand for aspire-managed dispatch\n        var manifestArgs = new List<string>\n        {\n            \"nuget\",\n            \"manifest\",\n            \"--assets\", assetsPath,\n            \"--output\", manifestPath,\n            \"--framework\", targetFramework\n        };\n\n        if (!string.IsNullOrEmpty(runtimeIdentifier))\n        {\n            manifestArgs.Add(\"--runtime-identifier\");\n            manifestArgs.Add(runtimeIdentifier);\n        }","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/NuGet/BundleNuGetService.cs#L191-L227","documentation":"RestorePackagesAsync runs `aspire-managed nuget restore` to restore the requested packages. A non-zero exit code indicates the restore itself failed; the method logs exit code, stderr and stdout, then throws InvalidOperationException 'Package restore failed: {error}' where {error} is the helper's stderr output.","triggerScenarios":"`nuget restore` helper exits non-zero during RestorePackagesAsync — e.g. package id/version not found on configured sources, authenticated feed rejected credentials, network failure, or invalid target framework/runtime identifier combination.","commonSituations":"Private feed credentials missing/expired; package version pinned in the AppHost that no longer exists on the source; corporate proxy or offline environment; wrong --source or nuget.config supplied.","solutions":["Read the stderr content in the exception message and the CLI error logs to find the underlying NuGet error","Verify the requested package id/version exist on the configured sources","Fix feed credentials (refresh PAT / install credential provider) and proxy settings","Retry; if the restore cache is corrupt, clear the package restore cache directory under the working directory"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-validate package ids/versions exist on the target feed\n// e.g. check https://api.nuget.org/v3-flatcontainer/{id}/{version}/{id}.{version}.nupkg","typeGuard":null,"tryCatchPattern":"try\n{\n    await service.RestorePackagesAsync(packages, workingDir);\n}\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Package restore failed\"))\n{\n    // read stderr in ex.Message; fix credentials/sources; retry\n}","preventionTips":["Verify requested package versions exist on the configured sources before restore","Keep NuGet credential providers and PATs fresh for private feeds","Configure proxy settings for NuGet in restricted networks","Use explicit --source/--nuget-config rather than relying on ambient config in CI"],"tags":["nuget","restore","network","feed"],"backgroundTag":"http-request-failed","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}