Project Order in Visual Studio Solution

Visual StudioProjects and-Solutions

Visual Studio Problem Overview


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?

Visual Studio Solutions


Solution 1 - Visual Studio

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.

Solution 2 - Visual Studio

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.

Solution 3 - Visual Studio

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.

Solution 4 - Visual Studio

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)

Solution 5 - Visual Studio

Per this solution: https://stackoverflow.com/a/21118705/835561

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.

Solution 6 - Visual Studio

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKent BoogaartView Question on Stackoverflow
Solution 1 - Visual StudioJeeva SubburajView Answer on Stackoverflow
Solution 2 - Visual StudioSamView Answer on Stackoverflow
Solution 3 - Visual StudioLeonid SternbergView Answer on Stackoverflow
Solution 4 - Visual StudioBenjolView Answer on Stackoverflow
Solution 5 - Visual StudioEdynView Answer on Stackoverflow
Solution 6 - Visual StudioMar TinView Answer on Stackoverflow