Alexander Zeitler

Alexander Zeitler

Rename Visual Studio project including files, folders and namespaces

Published on Friday, January 29, 2016


It's 2016 and Visual Studio doesn't support us in renaming Projects including files, folders and namespaces.

Considering you have a Visual Studio solution named PDMLab.AwesomeProject.WithAnUglyTypo and this solution contains multiple projects all starting with PDMLab.AwesomeProject.WithAnUglyTypo. The projects also may contain default namespace names starting using the solution name and the assemblies might be named accordingly.

One solution is to use Notepad++ to replace every occurrence of PDMLab.AwesomeProject.WithAnUglyTypo and rename the folders by hand or another tool.
Well, this works but I'm more a console user...

That said, the solution shown below asumes you have git bash installed.

Replacing the contents like namespaces in the files:

# run this in the root folder of your project
find . -name "*.*" -print0 | xargs -0 sed -i '' -e 's/PDMLab\.AwesomeProject\.WithAnUglyTypo/PDMLab.AwesomeProject.WithoutAnUglyTypo/g'

Renaming files and folders:

# run this in the root folder of your project
for i in $(find * -maxdepth 1); do mv $i $(echo $i | sed 's/PDMLab\.AwesomeProject\.WithAnUglyTypo/PDMLab.AwesomeProject.WithoutAnUglyTypo/'); done

The advantage of this solution: You can create an alias for both commands that expects the old and new name as an param and you're done.

Make sure you have a backup of your files before you try that - I'm not responsible if something goes wrong...

Happy renaming :)

What are your thoughts about "Rename Visual Studio project including files, folders and namespaces"?
Drop me a line - I'm looking forward to your feedback! email
Imprint | Privacy