1

What would be a sequence of operations to rename an MVC3 project directory in Visual Studio 2010? I can rename a project without any problems. However, if I try to detach it from solution and rename the directory containing it, attaching it back fails.

  • possible duplicate of [How do I rename a Project Folder from within Visual Studio?](http://stackoverflow.com/questions/211241/how-do-i-rename-a-project-folder-from-within-visual-studio) – Tim Abell May 23 '14 at 22:28

2 Answers2

5

Method to preserve references:

  • Rename project in Visual Studio (references should be updated to new name)
  • Close Visual Studio
  • Rename Directory
  • Edit Solution.sln in text editor--change directory referencing renamed project
  • Reopen solution and build

Assumtions:

  • project named DataAccess is renamed to DataAccess2
  • project directories located at src\ relative to the solution directory

Original:

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataAccess", "src\DataAccess\DataAccess.csproj", "{030E25DF-77F2-012E-94EC-4E4D7D1C62E8}"

After renaming project, before editing .sln:

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataAccess2", "src\DataAccess\DataAccess2.csproj", "{030E25DF-77F2-012E-94EC-4E4D7D1C62E8}"

After editing .sln:

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataAccess2", "src\DataAccess2\DataAccess2.csproj", "{030E25DF-77F2-012E-94EC-4E4D7D1C62E8}"
Mr.Mindor
  • 4,079
  • 2
  • 19
  • 25
  • disclaimer: I do have Resharper and it is possible the reference updating that occurs with the rename is handled by resharper and not VS. – Mr.Mindor Oct 07 '11 at 19:50
  • Nice works well. I don't have Resharper and the project reference was updated by VS. – MLF Oct 07 '11 at 20:00
  • Just realized this does not update the namespace(s), assembly name, or Assembly info in the Project properties tab. If this is desired it should be part of step 1 – Mr.Mindor Oct 07 '11 at 20:30
  • Doesn't work for me. VS still stores absolute paths somewhere. When I open the solution after all these steps it complaints that it cannot load the project that I moved. I have to clarify: it's an MVC3 project. – Reality Analyst Oct 07 '11 at 21:27
  • @Reality Analyst, in your MVC3 solution, which project did you move? Did you save the .sln before reopening the VS? The solution I modified was also an MVC3 project. – Mr.Mindor Oct 07 '11 at 21:37
  • also to note, the renaming the project (inside VS, 1st 2 bullets) and the moving of the project directory (VS closed, 3rd and 4th bullets) are separate tasks, you can do either one independently, or in reverse order. – Mr.Mindor Oct 07 '11 at 21:48
  • I'm trying to move the main MVC project. I've just tried your procedure on a new solution and it worked. I have no idea why it doesn't work on my original application. Maybe it's because I've added entity schema to it, or something like that. – Reality Analyst Oct 10 '11 at 13:26
0

I usually do this:

  • Rename the project in Solution Explorer in Visual Studio
  • Remove the project from the Solution in Visual Studio
  • Rename the project folder on the file system
  • Add the project back to the Solution in Visual Studio

Downside is you will lose any project references and you will have to redo them.

MLF
  • 626
  • 4
  • 15