Skip to content

Instantly share code, notes, and snippets.

@n3dst4
Last active February 21, 2024 13:56
Show Gist options
  • Save n3dst4/b932117f3453cc6c56be to your computer and use it in GitHub Desktop.
Save n3dst4/b932117f3453cc6c56be to your computer and use it in GitHub Desktop.
How to rename Visual Studio solutions and projects

How to rename solutions and projects in Visual Studio

  1. Don't.

How to rename solutions and projects that were created in Visual Studio

  1. Close Visual Studio and don't open it again until I tell you. Visual Studio is not competent at renaming things.

  2. Assuming you're using git, clean the working folder to remove anything that's not in version control (this will help the search-and-replace step because it won't have to go through a bunch of generated files)

    git clean -fdx

  3. Rename the solution file (.sln), the project folders, and the project files (.csproj, .fsproj)

  4. Open the project folder in any good text editor.

  5. Search-and-replace across the whole folder and replace and text occurrences of the old name with the new name. Sublime Text and Atom have a tree view where you can right click -> Search in folder. Notepad++ has a "Find in files" option.

  6. Hunt around for any weirdly mis-spelt versions of the old name that may not have been caught by the search-and-replace.

  7. Specifically, look for a package.nuspec (Nuget package manifest) and check the package name in there. It should probably be the same as the solution.

  8. (Finally) Open VS again and see if the project loads.

  9. See if it builds.

  10. Commit and push everything.

  11. Don't forget to update any corresponding servcies and integrations, such as:

    • Github repositories
    • Continuous Integration configs

Update 2020-09-04

ModernRonin has written an automated tool for doing this - give it a go before trying the manual steps here, and let us know how it goes!

https://github.com/ModernRonin/ProjectRenamer

https://www.nuget.org/packages/ModernRonin.ProjectRenamer/

@ModernRonin
Copy link

ModernRonin commented Sep 16, 2020

the tool has been updated to deal with a few more cases

@ModernRonin
Copy link

the tool can now also move projects to a different directory

@alex-hash
Copy link

Amazing work 👍

@Andy-AO
Copy link

Andy-AO commented Dec 21, 2021

It feels like msbuild has deeply coupled the names of the project and the file, which is undoubtedly a bad design.

@ethanhutchins33
Copy link

Thanks, this worked for me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment