Skip to content

Instantly share code, notes, and snippets.

@n3dst4
Last active February 21, 2024 13:56
Show Gist options
  • Star 98 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • 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/

@Eliranco7
Copy link

Thank you n3dst4 . That was the only thing (among all the garbage out there) which really helped me.

@arthurleonyy
Copy link

Thanks, i got here through google.
Worked perfectly.

@szalapski
Copy link

szalapski commented Jan 22, 2020

Where would you recommend actually changing the names of the folders on disk? I'm going to try doing this between steps 7 and 8.

@n3dst4
Copy link
Author

n3dst4 commented Jan 22, 2020

@szalapski I have that in step 3... I haven’t found a way to automate renaming folders so I just renamed in explorer as you’d normally rename a folder.

@petercook24
Copy link

worked like a charm. thanks!

@dtekchandani
Copy link

@n3dst4 Best place to visit for renaming projects. Thank you for the steps.

@ArmaanMcleod
Copy link

You could also get rid of the old .dll files in the bin and obj folders as well. You can do this by deleting those folders and rebuilding the solution. However, having those old files sticking around won't affect anything.

@mostafashawki
Copy link

Great, thanks :)

@codingfab
Copy link

Fantastic! Thanks a lot for that, great help 😍

@aronyanez
Copy link

Thanks :)

@SudiDav
Copy link

SudiDav commented Mar 24, 2020

Merci beaucoup!!!👌👍✌

@jimluschen
Copy link

Hahahaha, I really like Step 1! That's really the best part of this advice. I will now try it out...

@Florent125
Copy link

Very useful, thx

@miratrafikov
Copy link

🙏🥰

@gtsalter
Copy link

two VS Code projects (React/Git) where the business renamed the project after I started - worked like a champ! Thanks!! only additional was
git remote set-url origin [https://to-your-repo-here]

@simspace-dev
Copy link

Worked great. Thanks! 🍻

@luanholiv
Copy link

Thank you!

@sashaboy779
Copy link

thanks)

@Foizman
Copy link

Foizman commented Jul 23, 2020

Thank you !

Well, the tricky part of cause here is not loosing the Github-history.
Hence I made a short demo-video on how to achive it easily:

English version: https://youtu.be/J62q-YtNkas
German version: https://youtu.be/nburYkNXGGQ

@jpalvis86
Copy link

Great explanation!

Saved me (and many others as I see the comments) a lot of time and frustration.

Thanks a lot!

@AlejandroMFe
Copy link

Thanksss!!!

@apopovic
Copy link

Thank you. 👍

@ModernRonin
Copy link

I just solved this problem for myself writing a global dotnet tool. You can see whether it works for your case, too:

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

Cheers,
MR

@n3dst4
Copy link
Author

n3dst4 commented Sep 4, 2020

Thanks @ModernRonin. I've linked your project in the gist.

@ModernRonin
Copy link

ModernRonin commented Sep 4, 2020

👍

@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