Skip to content

fix(rename): unload referencing projects before rewriting their .csproj#79

Merged
CalvinAllen merged 1 commit intomainfrom
fix/rename/unload-referencing-projects
Apr 16, 2026
Merged

fix(rename): unload referencing projects before rewriting their .csproj#79
CalvinAllen merged 1 commit intomainfrom
fix/rename/unload-referencing-projects

Conversation

@CalvinAllen
Copy link
Copy Markdown
Contributor

Summary

  • When a renamed project has dependents, VS holds a file handle on each referencing .csproj (workspace / file watchers / design-time build). Step 9 ("Updating Project References") would then fail with The process cannot access the file because it is being used by another process, leaving the rename in a partially applied state.
  • ProjectReferenceService.UpdateProjectReferences now unloads each referencing project via IVsSolution4.UnloadProject before rewriting its XML, and reloads it in a finally block.
  • Unload failures (missing GUID, service unavailable, HRESULT failure) fall through to the previous direct-save behavior — this change never regresses the prior code path.

Test plan

  • Open a solution with Project B that has a ProjectReference to Project A
  • Rename Project A with Renamify — verify step 9 completes without the file-lock error
  • Confirm Project B's .csproj has the updated reference path and reloads cleanly in Solution Explorer
  • Rename a project with no dependents — verify step 9 is a no-op (same as before)
  • Try on both .sln and .slnx solutions in VS 2022 and VS 2026

Resolves #78

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.
@CalvinAllen CalvinAllen merged commit 087e9e3 into main Apr 16, 2026
2 checks passed
@CalvinAllen CalvinAllen deleted the fix/rename/unload-referencing-projects branch April 16, 2026 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

The process cannot access the file

1 participant