views:

125

answers:

3

I have a c# project wrapped in a solution. When I created the project I wrongly ticked the "Create directory for solution" check-box. I would now like to relocate the .sln file to the same folder as the project. Problem is, if I just move it in (and change the project path inside with a text editor) I get all sorts of build errors when opening the solution. I have also tried creating a new solution and "adding an existing project", but this also causes similar build errors.

Any suggestions how to handle this situation?

Thanks!

A: 

You can try to manually edit the .sln file or the project files, in order to adjust the paths appropriately after you move the solution to the directory you want. Of course having a backup of any modified file is highly advisable.

Konamiman
A: 

At the solution node of the Solution Explorer pane, select 'top menu -> file -> save soln as..'. Save the solution file in the same folder as your project (assuming that's what you want).

Close everything. Move the project folder out of the solution folder.

Worked for me before but if you hard coded some absolute paths in your code or referenced assemblies/projects, you might have to fix those after opening the solution in VS.

PS: Backup first before trying. :P

o.k.w
Thanks! Very easy this way.
JannieT
+1  A: 

I find that manual editing is straightforward and always solves these kinds of niggling problems.

The project file does not contain any reference to any containing solution, so that does not need to be touched.

The solution file does need editing, as follows:

  • Each Project entry contains a relative path to the project, whcih must obviously be set correctly.
  • The Global / GlobalSection(SourceCodeControl) entry contains either relative or absolute source code control paths to each project, which must also be adjusted.

That's it. There's nothing magic in there to trip you up, you just have to get those two bits correct.

When you load your edited solution file in Visual Studio, it will probably throw up several message boxes complaining that it can't find source control bindings etc, depending on what you changed. Just ignore these and plough on. When the solution has finished loading, go to the File / Source Control / Change Source Control dialog and correct any missing bindings.

Christian Hayter