Skip to content

Update the PM UI when a successful restore finishes - #7209

Merged
martinrrm merged 5 commits into
devfrom
dev-martinrrm-refresh-pmui-on-restore
Apr 7, 2026
Merged

martinrrm merged 5 commits into
devfrom
dev-martinrrm-refresh-pmui-on-restore

Conversation

@martinrrm

@martinrrm martinrrm commented Mar 12, 2026 •

Copy link
Copy Markdown
Contributor

Bug

Fixes: NuGet/Home#14761

Description

This is a proposal fix for NuGet/Home#14761, currently we don't directly watch for files saves, instead we do something like this:

If the file save causes CPS/project system nomination, the path is:

  1. VS project system detects project/props change
  2. project system nominates restore
  3. restore nomination reaches VsSolutionRestoreService
    4. AddProjectRestoreInfo(...) updates ProjectSystemCache
  4. CacheUpdated fires
  5. VSSolutionManager.AfterNuGetCacheUpdated fires
  6. PM UI refreshes through OnNuGetCacheUpdated
image

Refresh PM UI on restore completion instead of cache nomination

The Package Manager UI previously refreshed via AfterNuGetCacheUpdated, which fires during nomination (pre-restore) — meaning the UI would refresh with stale data
before the restore had actually written updated assets files.

This PR replaces that mechanism with IVsNuGetProjectUpdateEvents, which fires after restore completes and assets files are written:

  • ProjectUpdateFinished — per-project, post-restore signal. Only fires for non-no-op restores (guarded by !isNoOp in RestoreRunner.CommitAsync). Also fires for
    packages.config install/uninstall via PackageProjectEvents.BatchEnd.
  • SolutionRestoreFinished — solution-level, post-restore signal. Used for solution-level PM UI, but only triggers a refresh if at least one ProjectUpdateFinished
    fired during that restore cycle (skips full no-op restores).

Key changes

File Change
PackageManagerControl.xaml.cs Replace AfterNuGetCacheUpdated subscription with IVsNuGetProjectUpdateEvents.ProjectUpdateFinished and SolutionRestoreFinished
PackageManagerControl.xaml.cs Add _projectUpdateOccurredDuringRestore flag so solution-level PM UI skips refresh on full no-op restores
PackageManagerControl.xaml.cs Add deferred refresh: when PM UI is not visible during restore, set _isRefreshRequired = true and refresh on next Loaded event
PackageManagerUIRefreshEvent.cs Add RestoreCompleted to RefreshOperationSource telemetry enum
VsRestoreProgressEventsTests.cs Add 4 tests: exception isolation and multi-subscriber support for EndProjectUpdate and EndSolutionRestore
NuGetTelemetryServiceTests.cs Add 3 telemetry test cases for RestoreCompleted (Success, NoOp, NotApplicable)

Behavior summary

Scenario Old (CacheUpdated) New (ProjectUpdateFinished) Nikolche comment
PackageReference restore (non-no-op) ✅ but stale (pre-restore) ✅ fresh (post-restore) Correct.
PackageReference restore (no-op) ✅ fires anyway ❌ skipped — no unnecessary refresh No, there was no restore listener. The refresh happens at the end of ExecuteAction
packages.config install/uninstall ❌ not fired ✅ covered via BatchEnd Correct, but ExecuteAction handles a refresh through PM UI.
Solution full no-op restore ✅ fires anyway ❌ skipped via _projectUpdateOccurredDuringRestore No, there was no restore listener. The refresh happens at the end of ExecuteAction
PM UI hidden during restore Ignored, stale on return Deferred — _isRefreshRequired triggers refresh on Loaded Correct

How it works

  • Project-level PM UI: OnProjectUpdateFinished filters by matching projectUniqueName against the viewed project. Refreshes immediately if visible, defers if
    hidden.
  • Solution-level PM UI: OnProjectUpdateFinished sets _projectUpdateOccurredDuringRestore = true. OnSolutionRestoreFinished checks this flag — only refreshes if
    at least one project had a real restore. This avoids both N-per-project refreshes and unnecessary refreshes on full no-op restores.
  • During install/uninstall actions: _isExecutingAction gates all refresh signals; single refresh happens in ExecuteAction finally block (no double refresh).

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@martinrrm
martinrrm requested a review from a team as a code owner March 12, 2026 19:08

@jebriede jebriede left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martinrrm it looks like you're going to explore refreshing when a project has been updated instead of when the restore completes. Please request rereviews and update the PR description when that's ready. Thanks!

@martinrrm
martinrrm requested a review from nkolev92 March 23, 2026 21:38
Use _projectUpdateOccurredDuringRestore flag to track whether any
project had a non-no-op restore. Solution-level PM UI only refreshes
in OnSolutionRestoreFinished if the flag is set, avoiding unnecessary
refreshes when the entire restore was a no-op.

Also reorder OnProjectUpdateFinished to check Model.IsSolution first,
setting the flag for solution-level PM UI before checking visibility.

Co-authored-by: Copilot <[email protected]>
@martinrrm
martinrrm requested a review from jebriede March 23, 2026 21:39
@martinrrm
martinrrm force-pushed the dev-martinrrm-refresh-pmui-on-restore branch from ad08b79 to 2b6ba07 Compare March 23, 2026 22:01
@martinrrm martinrrm changed the title [Proposal?] Update the PM UI when a successful restore finishes Update the PM UI when a successful restore finishes Mar 30, 2026
@nkolev92

nkolev92 commented Apr 1, 2026

Copy link
Copy Markdown
Member

I think the scenario table is mostly incorrect about the old behavior.

Scenario Old (CacheUpdated) New (ProjectUpdateFinished) Nikolche comment
PackageReference restore (non-no-op) ✅ but stale (pre-restore) ✅ fresh (post-restore) Correct.
PackageReference restore (no-op) ✅ fires anyway ❌ skipped — no unnecessary refresh No, there was no restore listener. The refresh happens at the end of ExecuteAction
packages.config install/uninstall ❌ not fired ✅ covered via BatchEnd Correct, but ExecuteAction handles a refresh through PM UI.
Solution full no-op restore ✅ fires anyway ❌ skipped via _projectUpdateOccurredDuringRestore No, there was no restore listener. The refresh happens at the end of ExecuteAction
PM UI hidden during restore Ignored, stale on return Deferred — _isRefreshRequired triggers refresh on Loaded Correct

@nkolev92 nkolev92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Small comment.

@martinrrm
martinrrm requested a review from nkolev92 April 6, 2026 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug Bash] [Unstable] The ‘Installed’ tab was not refreshed after fixing the NuGet package vulnerabilities with GitHub Copilot

3 participants