Project Order in Visual Studio Solution

后端 未结 6 1053
我在风中等你
我在风中等你 2021-02-01 01:13

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 an

相关标签:
6条回答
  • 2021-02-01 01:17

    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.

    0 讨论(0)
  • 2021-02-01 01:19

    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)

    0 讨论(0)
  • 2021-02-01 01:22

    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.

    0 讨论(0)
  • 2021-02-01 01:32

    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 讨论(0)
  • 2021-02-01 01:37

    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.

    0 讨论(0)
  • 2021-02-01 01:39

    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.

    0 讨论(0)
提交回复
热议问题