开发者

Project Order in Visual Studio Solution

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开发者_Go百科 projects are being displayed?


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.


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.


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.


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)


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.


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
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜