开发者

Changing The Name Of A C# Project Folder?

I have a main project directory with the following conten开发者_运维技巧ts:

SubDirectory (Directory)

Project.sln (Solution File)

When I try manually changing SubDirectory's name in my Windows explorer, I get errors when I open the solution file. How can I rename this directory without affecting my solution?

Thanks!


Rename it in Visual studio, or edit the .csproj/.sln file with a text editor and fix the refrences.


Open the solution file in a text editor and rename all references to the old folder.


Open up the .sln file in notepad. You'll see a line like this:

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "myproject", "myproject\myproject.csproj", "{DF81752F-37EE-4F4E-BC22-B09C8D05ED78}"
EndProject

If you want to rename the folder from myproject to newproject, you can change myproject\myproject.csproj to newproject\myproject.csproj (or whatever).


Change the name in SolutionExplorer.. it will work fine..

However it doesn't gurantee problem with Source Control or TFS you will need to resolve them manually


Your solution has the paths to your project files embedded in it, which includes the folder name. If you want to rename the folder, you have three options:

  1. Close the solution. Rename the folder, then reopen the solution. The projects will show up as gray, and you'll need to click each one and locate the project file in the Properties window. Note that this may remove project references, but it may not. This is what I would suggest.
  2. Open the solution and remove the project(s) within that directory. Note that this will remove any project references from any other projects that reference the project(s) that you're removing. Rename the folder, then add the project (and any project references) back.
  3. Close the solution. Rename the folder, then open the .sln file in Notepad (or some other text editor) and fix the paths manually. This will preserve any project references.


When I have done it, I manually change it, then open the solution. You will get an error about not being able to find the project file, just choose to locate it, and it will re-map it. If you are using VSS, make sure everything is checked in first.


There are probably paths in project/solution related files that contain the old directory name. You'll either have to update those manually or find a way to rename the project from within Visual Studio.

This might help you rename the project: http://msdn.microsoft.com/en-us/library/3e92t91t%28v=VS.90%29.aspx


  • In Visual Studio solution explorer, edit the project properties to change the assembly name, namespaces etc. etc. to what you want.
  • Rename the top Project nodes in VS solution explorer.
  • Shut Visual Studio down.
  • Open Windows explorer and rename your folders and .csproj files to what you want.
  • With a text editor and NOT Visual Studio, open up the
    • sln file,
    • the .csproj files and
    • anything else you've renamed.
  • do a Find & Replace looking for the old project strings, filenames, namespaces (if required - I suggest you leave that bit for when all has been transitioned) and replacing them as required.
    I'm suggesting you'll need to be selective because I don't know how you've named your projects and .csproj files ;-)

Once you've done all that, quit your text editor and try opening up your .sln file again.

  • Do a Rebuild the first time to remove any artifacts from the old configuration/naming.

HTH

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜