visual-studio Visual Studio 解决方案中的项目顺序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2244765/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Project Order in Visual Studio Solution
提问by Kent Boogaart
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.
在 Visual Studio 2008 中,什么决定了项目在解决方案文件夹中的显示顺序?这不是字母顺序,也不是构建顺序。
I cannot find any way of altering the order in which projects are being listed. I've tried removing my .suofile, as well as moving things about in the .slnfile. Neither had any effect.
我找不到任何改变项目列出顺序的方法。我试过删除我的.suo文件,以及移动.sln文件中的内容。两者都没有任何影响。
How can I change the order in which my projects are being displayed?
如何更改我的项目的显示顺序?
采纳答案by Jeeva Subburaj
There is a feedback Request already placed at Connect.Microsoft.com so, you will have to wait for the permanent solution.
Connect.Microsoft.com 上已经有一个反馈请求,因此您必须等待永久解决方案。
http://connect.microsoft.com/VisualStudio/feedback/details/468874/solution-explorer-project-sort-order(replaced with Wayback Machine link as original was removed)
http://connect.microsoft.com/VisualStudio/feedback/details/468874/solution-explorer-project-sort-order(替换为原版的 Wayback Machine 链接)
Temporary workarounds are available but not good enough I feel. One of them is:
临时解决方法可用,但我觉得还不够好。其中之一是:
Press F2to rename a project, then press Enterwithout changing the name. This temporarily sorts the projects within that folder.
按F2重命名项目,然后按Enter而不更改名称。这会临时对该文件夹中的项目进行排序。
Or use http://solutionsorter.codeplex.com/to alter SLN for permanent fix if your solution folders are not nested(it ate my solution)
或者,如果您的解决方案文件夹不是嵌套的,则使用http://solutionsorter.codeplex.com/更改 SLN 以进行永久修复(它吃了我的解决方案)
But this will not work if you close and open the solution.
但是,如果您关闭并打开解决方案,这将不起作用。
If you use Resharper, you can press the short cut CTRL+ Nto find out files in solution and CTRL+ F12to find out methods in the file.
如果您使用 Resharper,您可以按快捷键CTRL+N查找解决方案中的文件,并按CTRL+F12查找文件中的方法。
回答by Sam
Unfortunately VS2010 forces projects to be alphabetically sorted.
不幸的是,VS2010 强制项目按字母顺序排序。
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.
也许通过添加数字前缀(01、02、03 等)来重命名项目以实现所需的顺序是唯一的解决方法,尽管也不理想。
回答by Leonid Sternberg
Take file .sln in any text editor.
Order the parts
"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "etc..."
...
EndProject
在任何文本编辑器中获取文件 .sln。订购零件
“ 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.
以您想要的任何顺序。保存。就这样。下次您打开此解决方案时,项目将按该顺序排列。
回答by Benjol
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):
使用此 F# 脚本按字母顺序对其进行排序(根据需要更改文件路径):
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)
(如果你只有几个项目,就手动排序)
回答by Edyn
Per this solution: https://stackoverflow.com/a/21118705/835561
根据此解决方案: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.
您可以使用解决方案文件夹进行排序,而不必担心它会影响项目依赖项。不确定这在 2013 年之前的效果如何,但我遇到了这个寻找 2013 年的问题,并认为这可能会帮助我的情况下的其他人。

