{"record":{"id":"ffe4bbe96c1a341f","repo":"microsoft/aspire","slug":"failed-to-restore-packages-for-project-projectfile-fullname","errorCode":null,"errorMessage":"Failed to restore packages for project {projectFile.FullName} after update.","messagePattern":"Failed to restore packages for project (.+?) after update\\.","errorType":"exception","errorClass":"ProjectUpdaterException","httpStatus":null,"severity":"critical","filePath":"src/Aspire.Cli/Projects/ProjectUpdater.cs","lineNumber":197,"sourceCode":"        // feed, but the rest are still on their previous (often stable) versions which may\n        // not be carried by that feed. Mapping then blocks the fallback to nuget.org, producing\n        // NU1103 for every not-yet-bumped Aspire reference. Deferring the restore until all\n        // edits are applied means every Aspire* reference resolves against versions that\n        // exist in the configured feed.\n        // Restoring the AppHost project transitively restores referenced projects, so a single\n        // restore here covers both traditional PackageReference and Directory.Packages.props\n        // (CPM) update paths. The 'dotnet restore' command accepts both .csproj and file-based\n        // (apphost.cs) program files as the positional argument.\n        // See https://github.com/dotnet/aspire/issues/15891.\n        await interactionService.ShowStatusAsync(\n            UpdateCommandStrings.RestoringPackagesAfterUpdate,\n            async () =>\n            {\n                var restoreExitCode = await runner.RestoreAsync(projectFile, new(), cancellationToken);\n\n                if (restoreExitCode != 0)\n                {\n                    throw new ProjectUpdaterException(string.Format(CultureInfo.InvariantCulture, UpdateCommandStrings.FailedToRestoreAfterUpdateFormat, projectFile.FullName));\n                }\n\n                return 0;\n            });\n\n        interactionService.DisplayEmptyLine();\n\n        interactionService.DisplaySuccess(UpdateCommandStrings.UpdateSuccessfulMessage);\n        return new ProjectUpdateResult { UpdatedApplied = true };\n    }\n\n    private static bool IsGlobalNuGetConfig(string path)\n    {\n        if (Environment.OSVersion.Platform == PlatformID.Win32NT)\n        {\n            return path.StartsWith(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), StringComparison.Ordinal);\n        }\n        else","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Projects/ProjectUpdater.cs#L179-L215","documentation":"After applying package updates to the project file, ProjectUpdater runs dotnet restore to bring the project back to a consistent state. If the restore command exits non-zero it throws ProjectUpdaterException with FailedToRestoreAfterUpdateFormat including the project path. The update itself was written, but the project no longer restores cleanly.","triggerScenarios":"UpdateProjectAsync's post-update step where runner.RestoreAsync(projectFile, ...) returns a non-zero exit code — restore fails with the newly written package versions (conflicts, unreachable feed, broken transitive dependency).","commonSituations":"Updated package version does not exist on the configured feed (stale/offline mirror); version conflicts introduced by bumping central package versions; private feed credentials expired; network outage during restore; incompatible transitive dependency set after the update.","solutions":["Run dotnet restore on the project manually and read the NU1xxx error to see the exact failing package or source.","Check the targeted feed is reachable and credentials are valid (nuget.org or your mirror).","If the update picked an incompatible version, revert or pin that package version in the project/Directory.Packages.props and retry the update.","Clear the NuGet cache for the failing package (dotnet nuget locals http-cache --clear) and retry in case of corrupted cache entries."],"exampleFix":"// before\n<PackageVersion Include=\"Aspire.Hosting.Redis\" Version=\"13.0.99\" />  // never published\n// after\n<PackageVersion Include=\"Aspire.Hosting.Redis\" Version=\"13.0.2\" />","handlingStrategy":"retry","validationCode":"// Pre-check: verify key packages exist at the target versions before updating\nforeach (var pkg in packageIds)\n    await dotnet.RunAsync($\"package search {pkg} --exact-match\");","typeGuard":null,"tryCatchPattern":"try\n{\n    await updater.UpdateProjectAsync(context, cancellationToken);\n}\ncatch (ProjectUpdaterException ex) when (ex.Message.Contains(\"restore\"))\n{\n    // Revert the project file from backup, then retry after fixing feed/versions\n    File.Copy(projectFile.FullName + \".bak\", projectFile.FullName, overwrite: true);\n    Console.Error.WriteLine($\"Post-update restore failed: {ex.Message}\");\n}","preventionTips":["Keep a backup (or clean git tree) of project files before running updates so you can revert.","Ensure feeds are reachable and credentials current before updating packages.","Pin volatile packages so the updater doesn't select nonexistent versions.","Run dotnet restore first to confirm the project is healthy before an update."],"tags":["cli","nuget","restore","update"],"backgroundTag":"package-restore-failed","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"}