Repository navigation
[VSIntegration] ShadowDesigner: solve the "save solution?" prompt th… - #2183
Merged
RobertvanderHulst merged 1 commit intoNov 18, 2026
Merged
Conversation
…t might leave a stale companion. Move the caret inside a new event handler After using the designer, closing the solution always asked to save it, and answering No made VS 2026 report the companion project as not found on the next open.
RobertvanderHulst
deleted the
fix/shadow-designer-solution-save-prompt-v2
branch
November 18, 2026 15:21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Problem
After the shadow WinForms designer was used, closing the solution (or VS) always asked to save the solution file. Answering No made VS 2026 report on the next open: "The following projects from the solution were not found: ...{Project}.ShadowDesigner{Project}.ShadowDesigner.csproj". VS 2022 shows no dialog, but has the same stale entry.
Cause:
File.SaveAll, on dev nowSaveDirtyDocuments), so the solution file was saved with the companion in it, along with any unsaved change of the user's.With an unsaved solution change (for example a new solution folder), Ctrl+S in the designer also failed with "A recursive save operation is in progress for '....slnx'": the save of all documents runs inside VS's own
OnAfterSavecallback and tries to save the solution while VS is still in the first save.Changes
Solution close (
ShadowDesignerCleanup.cs,SolutionWiring.cs)OnQueryCloseSolution, which fires for every close: Close Solution, exiting VS, opening another solution.EnsureProjectInSolution) and removing it on close are saved right away only when the solution had no other unsaved changes. The companion then never causes a prompt, and the user's own unsaved changes still get the normal prompt.SolutionWiring:IsSolutionDirty(VSPROPID_IsSolutionDirty),GetSolutionFile,SaveSolutionFile(SaveSolutionElement(SLNSAVEOPT_SaveIfDirty), skipped for a never-saved solution).Solution file cleanup after close (new
SolutionFileCleanup.cs).slnx: the companion<Project>elements, and the "Shadow Designer (generated)"<Folder>once it is empty..sln: the companionProject ... EndProjectblocks with their configuration andNestedProjectslines, and the folder once nothing is nested in it.Saving before a sync (
CompanionSaveWatcher.cs)OnAfterSaveandOnBeforeDocumentWindowShownow save only the companion's own dirty.cs/.resxdocuments (SaveCompanionDocuments), which is all the syncs read from disk. The user's solution and other documents are no longer saved behind their back, and the recursive save error is gone.SaveDirtyDocuments(all documents) is kept for Debug/Start, where VS saves everything for the build anyway. Itssavingflag is now reset in afinally; before, a failed or cancelled save left it set and nothing was saved again for the rest of the session.OnAfterSavecalledTryHandleResxOnlySave(path)also whenpathis null or empty, sopath.EndsWithcould throw inside the RDT callback. That call is removed.Caret in a new event handler (
CompanionSaveWatcher.cs)EventHandlerSyncwrites the stub to the.prgon disk, but an already open.prgis only reloaded by VS when the UI thread is idle, which never happens while the new-handler redirect runs (JoinableTaskFactory.RuninOnBeforeDocumentWindowShow). The line number from the file then pointed past the end of the old buffer.RedirectNowAsyncnow reloads the open.prgfirst (ReloadOpenDocument:IVsPersistDocData.ReloadDocData(RDD_IgnoreNextFileChange)), only when it has no unsaved changes.NavigateToMethodAsyncsearches theMETHOD name(line in the editor buffer instead of the file, with a short poll as a fallback.Relation to 289fec7 and 884ce65
289fec7 addressed the same stale-companion problem. Its close handling is replaced here, for these reasons:
OnQueryCloseSolution, every close.slnxcleanupXmlDocumenton every close.slncleanupNestedProjectslines stay; BOM dropped;lines[i + 1]can run past the endSaveDirtyDocuments= all documents, from insideOnAfterSave(recursive.slnxsave).cs/.resxonlyKept as they are: the EnvDTE removal (884ce65), the save before Debug/Start, the event migration fix in
RoslynToCodeDom, and the newIVsTextView-based navigation (extended as described above).