DEV Community

Mattias Cibien
Mattias Cibien

Posted on

Rename a C# Project

One of the problems beginners face when using Visual Studio happens when they try to rename a project since there will be a lot of leftovers in the process. This can be a problem even for professionals if they find out that the project name cannot be used, for example, in patents or copyright situations. Today we are going to fully rename a Visual Studio Project.

Note: This guide works with every version of Visual Studio and every kind of .NET Project.

Step 1: Solution Name and Project Name

Renaming the solution is actually the simplest part of the process. Just click on the solution item in Solution Explorer twice (but do not double click) to get an editable field and then type the new name.

In most of the cases your project name will match your solution name so just repeat the steps on the project item instead of the solution.

Step 2: Folder Name

Renaming the project actually does not change the folder your project is contained. When you do the first step you will have this situation:

<root>
|- NewName.sln
|- OldName
   |- NewName.csproj (or vbporj, vcxproj...)
Enter fullscreen mode Exit fullscreen mode

In order to get the new name on the project folder you have to:

  1. Rename the folder itself
  2. Open the sln file with a text editor like notepad and do a Find&Replace to replace the old name with the new name.

Note: You can also remove the wrong project inside Soluton Explorer and add the correct one back.

Step 3: Executable or Library Name

Executable (or Library) Name is actually pretty easy to do: just right-click on your project in Solution Explorer and choose Properties.

In the application ta you will see the Assembly Name text box. Just change these and you are ready to go.

Step 4: Namespaces

You may not want to keep the namespaces containing the name of your application, especially if you are using a name that you cannot use.

To do this, first of all, change the Default Namespace in the project properties like you did in Step 3. and then you can use Find&Replace to change any reference to the old name in the new one.

Alternatively you can rename the namespace in one of your files and then use the refactoring tool (the little box appearing under the namespace when you edit it) to replace any reference.

Top comments (3)

Collapse
 
modernronin profile image
ModernRonin

Actually, you can just use a little utility I wrote that also deals with git (so the history doesn't get lost), paket (if you use it), moving projects to other directories etc.

Install via dotnet tool install -g ModernRonin.ProjectRenamer, see github.com/ModernRonin/ProjectRenamer for documentation.

Cheers,
MR

Collapse
 
dougedmunds profile image
dougedmunds

There are many files with the old namespace in the directories 'bin' and 'obj'. Is it safe to delete the bin and obj directories and let the system recreate them?

Collapse
 
mattiascibien profile image
Mattias Cibien

Bin and obj are temporary folders generated by the C# compiler. They can be safely deleted and should never be committed in Version Control. If you need something to quickly cleanup those I suggest the shell scripts that you can find on stackoverflow.com/questions/755382...