Project Order in Visual Studio Solution
Asked Answered
A

6

61

In Visual Studio 2008, what determines the order in which projects appear within a solution folder? It's not alphabetical order, nor is it build order.

I cannot find any way of altering the order in which projects are being listed. I've tried removing my .suo file, as well as moving things about in the .sln file. Neither had any effect.

How can I change the order in which my projects are being displayed?

Anglocatholic answered 11/2, 2010 at 13:43 Comment(1)
I have even worse situation. From time to time, VS 2008 decides to re-order my projects ... It awful, just when I used to "its order", it decides to changed and in a solution with more than 100 project, it's a nightmare finding anything!Fijian
D
13

There is a feedback Request already placed at Connect.Microsoft.com so, you will have to wait for the permanent solution.

http://connect.microsoft.com/VisualStudio/feedback/details/468874/solution-explorer-project-sort-order (replaced with Wayback Machine link as original was removed)

Temporary workarounds are available but not good enough I feel. One of them is:

Press F2 to rename a project, then press Enter without changing the name. This temporarily sorts the projects within that folder.

(As per http://social.msdn.microsoft.com/Forums/en-US/vssetup/thread/79d46a69-386e-4ad8-b9cb-b00d4252495b/?prof=required )

Or use http://solutionsorter.codeplex.com/ to alter SLN for permanent fix if your solution folders are not nested (it ate my solution)

But this will not work if you close and open the solution.

If you use Resharper, you can press the short cut CTRL + N to find out files in solution and CTRL + F12 to find out methods in the file.

Duality answered 11/2, 2010 at 13:56 Comment(2)
AFAIK it's fixed in VS2010, I expect that there won't be a permanent solution for VS2008.Tetrahedral
@Tetrahedral define "fixed"? always sorted alphabetically?Coprolalia
B
12

Unfortunately VS2010 forces projects to be alphabetically sorted.

Perhaps renaming the projects by adding a numerical prefix (01, 02, 03, etc) to achieve the desired order is the only workaround, although not ideal either.

Bosco answered 18/4, 2012 at 5:40 Comment(0)
H
7

Take file .sln in any text editor. Order the parts
" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "etc..."
...
EndProject

in any order you want. Save it. That's all. Next time you will open this solution the projects will be in THAT order.

Hellbender answered 21/2, 2011 at 18:23 Comment(1)
This doesn't have any effect in VS2010 (original question was about VS2008, but I just tried this in vain hopes it would work)Lobotomy
T
4

Hacky alternative: Copy out the section with these lines into a text file.

Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "etc..."
EndProject

Use this F# script to sort it alphabetically (changing file path as required):

open System.IO

let readlines p = File.ReadAllLines(p)
let writelines p lines = File.WriteAllLines(p, lines)

let startpos = @"Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = """.Length
let getProj (s:string) = s.Substring(startpos, s.IndexOf('"', startpos) - startpos)

let path = @"C:\Temp\sln.txt"
path |> readlines
    |> Array.filter (fun s -> s.StartsWith("Project"))
    |> Array.map (fun s -> (getProj(s), s))
    |> Array.sortBy fst
    |> Array.map snd
    |> Array.collect (fun s -> [|s;"EndProject"|])
    |> writelines path

(If you've only got a few projects, just sort it by hand)

Tetrahedral answered 8/11, 2010 at 11:15 Comment(0)
P
2

Per this solution: https://mcmap.net/q/330090/-visual-studio-how-to-arrange-the-projects-inside-solution-explorer-by-dependency

You can use Solution Folders to do your sorting without worrying about it affecting project dependencies. Not sure how well this works prior to 2013, but I came across this question looking for 2013 and thought this might help others in my situation.

Philpott answered 22/11, 2014 at 10:48 Comment(0)
M
0

The dotnet sln add command reorder all projects in all folders in solution for me.

Simply add at least one project with the following command to your solution:

dotnet sln $Solution add --solution-folder $SolutionFolder $projectPath

Or without a solution folder:

dotnet sln $Solution add --in-root $projectPath
Melville answered 11/12, 2020 at 8:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.