how to rename a project without killing solution

血红的双手。 提交于 2019-12-18 13:12:53

问题


When I rename a project within a solution, and then try and build that project, I get the error: "The project file "xyz.csproj" was not found. Where xyz is the old project file name!

The annoying thing is that I can search my project & solution for the old project file name, and the search will come up with nothing, and when I click on the error VS does nothing.

So there seems to be no way of finding where the old reference is.

This is a .web project hosting a silverlight page, if that makes any difference.


回答1:


These are steps I follow when I rename a project:

  1. Click on the project in the solution and rename it. This renames the .proj file and the project name(but not the directory containing the project).
  2. Close solution, rename the project folder. At this stage, the solution still references the old folder.
  3. Open sln file and replace the old folder name with the new one. This should only be in one place. it will look something like this.
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SolutionName", "OldProjectName\NewProjectName.csproj", "{98644DD0-5AB5-4CAC-8D83-CCB8EEEFE234}"

You will need to make it look like this:

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SolutionName", "NewProjectName\NewProjectName.csproj", "{98644DD0-5AB5-4CAC-8D83-CCB8EEEFE234}"



回答2:


With all visual studio projects, you can usually just close visual studio, edit the solution/project files with a text editor, and reopen visual studio. They're just XML. As long as you're careful not to change anything major, a search & replace in a text editor should do the trick.




回答3:


OK this was my problem. I deleted the service reference to the project I renamed, but still got the error message, then via some trial and error adding and removing projects I found that there is a "WCF Ria Services Link" Project property, doh.

That's a bit of a trap.




回答4:


I also had to rename the namespace and point the project's startup object to the renamed program:

<old_project>.Program to <new_project>.Program


来源:https://stackoverflow.com/questions/3209002/how-to-rename-a-project-without-killing-solution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!