fix(rename): unload referencing projects before rewriting their .csproj#79
Merged
CalvinAllen merged 1 commit intomainfrom Apr 16, 2026
Merged
Conversation
When a renamed project has dependents, Visual Studio keeps a file handle on each referencing .csproj (workspace, file watchers, design-time build). Writing through XmlDocument.Save would frequently fail with 'The process cannot access the file because it is being used by another process', leaving the rename in a partially applied state. Each referencing project is now unloaded via IVsSolution4.UnloadProject, rewritten, and reloaded in a finally block. If the unload cannot be performed (no GUID, service missing, HRESULT failure), we fall back to the previous direct-save behavior so this change never regresses.
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.
Summary
.csproj(workspace / file watchers / design-time build). Step 9 ("Updating Project References") would then fail withThe process cannot access the file because it is being used by another process, leaving the rename in a partially applied state.ProjectReferenceService.UpdateProjectReferencesnow unloads each referencing project viaIVsSolution4.UnloadProjectbefore rewriting its XML, and reloads it in afinallyblock.Test plan
ProjectReferenceto Project A.csprojhas the updated reference path and reloads cleanly in Solution Explorer.slnand.slnxsolutions in VS 2022 and VS 2026Resolves #78