Skip to content

Instantly share code, notes, and snippets.

@n3dst4
Last active January 13, 2025 16:46
Show Gist options
  • Select an option

  • Save n3dst4/b932117f3453cc6c56be to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

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

@arthurleonyy

Copy link
Copy Markdown

Thanks, i got here through google.
Worked perfectly.

@szalapski

szalapski commented Jan 22, 2020

Copy link
Copy Markdown

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

n3dst4 commented Jan 22, 2020

Copy link
Copy Markdown
Author

@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
Copy Markdown

worked like a charm. thanks!

@dtekchandani

Copy link
Copy Markdown

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

@ArmaanMcleod

Copy link
Copy Markdown

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
Copy Markdown

Great, thanks :)

@codingfab

Copy link
Copy Markdown

Fantastic! Thanks a lot for that, great help 😍

@aronyanez

Copy link
Copy Markdown

Thanks :)

@SudiDav

SudiDav commented Mar 24, 2020

Copy link
Copy Markdown

Merci beaucoup!!!πŸ‘ŒπŸ‘βœŒ

@jimluschen

Copy link
Copy Markdown

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

@Florent125

Copy link
Copy Markdown

Very useful, thx

@miratrafikov

Copy link
Copy Markdown

πŸ™πŸ₯°

@gtsalter

Copy link
Copy Markdown

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
Copy Markdown

Worked great. Thanks! 🍻

@luanholiv

Copy link
Copy Markdown

Thank you!

@sashaboy779

Copy link
Copy Markdown

thanks)

@Foizman

Foizman commented Jul 23, 2020

Copy link
Copy Markdown

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
Copy Markdown

Great explanation!

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

Thanks a lot!

@AlejandroMFe

Copy link
Copy Markdown

Thanksss!!!

@apopovic

Copy link
Copy Markdown

Thank you. πŸ‘

@ModernRonin

Copy link
Copy Markdown

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

n3dst4 commented Sep 4, 2020

Copy link
Copy Markdown
Author

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

@ModernRonin

ModernRonin commented Sep 4, 2020

Copy link
Copy Markdown

πŸ‘

@ModernRonin

ModernRonin commented Sep 16, 2020

Copy link
Copy Markdown

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

@ModernRonin

Copy link
Copy Markdown

the tool can now also move projects to a different directory

@alex-hash

Copy link
Copy Markdown

Amazing work πŸ‘

@Andy-AO

Andy-AO commented Dec 21, 2021

Copy link
Copy Markdown

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

@ethanhutchins33

Copy link
Copy Markdown

Thanks, this worked for me :)

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