Reality Analyst
Reality Analyst

Reputation: 77

Renaming project directory in VS 2010

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.

Upvotes: 1

Views: 2646

Answers (2)

Mr.Mindor
Mr.Mindor

Reputation: 4129

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}"

Upvotes: 5

MLF
MLF

Reputation: 619

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.

Upvotes: 0

Related Questions