Is it possible to rename a project in Visual Studi

2020-07-10 07:31发布

问题:

Let's assume we're working on a project called MyProject. I'd like to be able to change its name to MyProject2 AND have its folder name also renamed to MyProject2.

Is this possible from Visual Studio? If not, how to make this happen "outside" it?

回答1:

Rename your project to your new name. It will change the .csproj file automatically which in 2010 is the name of the project. Close Visual Studio. Rename the directory.

Open your solution file to change directory now. Your solution file will point to the new project but will reference the wrong directory.

Before:

 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stackoverflow_4560662_Rename",    "Stackoverflow_4560662\Stackoverflow_4560662_Rename.csproj", "{7CCD10BF-48BA-44E2-B071-D4ED8067ACA1}"

After

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stackoverflow_4560662_Rename", "Stackoverflow_4560662_Rename\Stackoverflow_4560662_Rename.csproj", "{7CCD10BF-48BA-44E2-B071-D4ED8067ACA1}"

Notice the two parts "Stackoverflow_4560662\Stackoverflow_4560662_Rename.csproj" becomes "Stackoverflow_4560662_Rename\Stackoverflow_4560662_Rename.csproj"

This is the only way I've been able to rename a directory for a project. I hope someone finds a better answer.



回答2:

Following may be one solution

  • Close the solution.
  • Rename the folders outside Visual Studio.
  • Open the solution, ignoring the warnings.
  • Go through all unavailable projects.
    • Set the property 'File Path' to the new location.
    • Reload the project.
    • In case you didn't rename the project, rename it (F2).

Check answer

How do I rename a Project Folder from within Visual Studio?



回答3:

I'm pretty much a novice at this stuff but I had the same issue, my resolution was to just copy and paste my code into a new project and save it using the new name I needed. Probably not the best method but it's simple and it works.



回答4:

Not sure if this helps anybody but all I did was rename the solution and associated folders etc. Unfortunately when you open it says it can't find your project(s). To get around this I opened the solution itself in a text editor (notepad++) and renamed where it finds the Project . . . and it works.

Andy



回答5:

Assuming you're talking about a single VB.NET project in a solution.

AFAIK, You're not supposed to rename the 'My Project' folder, that's the VS default name for all VB.NET project.

Just select the project/solution in VS Solution Explorer and Click F2 to simply rename it.