C#: Rename a project in Visual Studio

Renaming projects in Visual Studio is a pain in the @$$ and can be really time consuming if you don’t know what you’re doing. Visual Studio 2008 doesn’t come with a good refactoring tool for project renaming and the solution files can really cause problems if you don’t edit them properly.

I’ll create a somewhat fake project for this example:

Our test project
Our test project


When the project is created, right-click on the project and rename it from BadNameProject to GoodNameProject:

Now the project is properly named to GoodNameProject, almost. Right-click on the project and go to properties:

As you can see the Assembly name and Default namespace hasn’t change name so you need to change these as well.

Now, right-click on the project once more and select Open folder in Windows explorer, you need to rename the folder to the project as well and configure the solution file.

Rename the folder
Rename the folder

Right-click on the TestProject.sln file and select to edit it with a proper tool (such as NotePad++), you will see something like this:

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BadNameProject", "BadNameProject\BadNameProject.csproj", "{9E1B883A-025C-47AD-9350-D4CAD2760517}"
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{9E1B883A-025C-47AD-9350-D4CAD2760517}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{9E1B883A-025C-47AD-9350-D4CAD2760517}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{9E1B883A-025C-47AD-9350-D4CAD2760517}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{9E1B883A-025C-47AD-9350-D4CAD2760517}.Release|Any CPU.Build.0 = Release|Any CPU
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE

Change references from the old BadNameProject to the new GoodNameProject.

When you return to Visual Studio you will be prompted to take action against the outside changes to the solution file. If you want to save your old project do so, but Discard is what you want to choose here and embrace your new changes!


Tadaa, you’re pretty much done. Depending on how much refactoring you need to do of course, don’t forget to change the project namespaces in your files…

Tip: If you have to change a lot of references from the old namespace to the new, use the SHIFT + CTRL + F12 debugging tool (jump to next error) to quickly add new references.