visual-studio 如何在 Visual Studio 中显示我的项目包含多少行代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/827127/
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
How do I show how many lines of code my project contains in Visual Studio?
提问by KingNestor
Possible Duplicate:
How do you count the lines of code in a Visual Studio solution?
How can I show the code metrics window in Visual Studio 2008 Professional SP1? I'm looking to see how many total lines of code my project is for school and I can't find it.
如何在 Visual Studio 2008 Professional SP1 中显示代码度量窗口?我想看看我的项目总共有多少行代码供学校使用,但我找不到。
The help file said to go to View->Other Windows->Code Metrics, but this option is not available to me. I also tried right-clicking the project in the Solution Explorer to see if there was an option but there wasn't.
帮助文件说转到查看-> 其他 Windows-> 代码指标,但我无法使用此选项。我还尝试在解决方案资源管理器中右键单击该项目以查看是否有选项但没有。
Where is this mythical unicorn of a feature? If the Pro version doesn't have this feature has anyone found a simple external method to count the lines in all .cs files in an automated way?
这个功能的神话独角兽在哪里?如果 Pro 版本没有此功能,是否有人找到了一种简单的外部方法来自动计算所有 .cs 文件中的行数?
采纳答案by BQ.
Code Metrics is only available in the Team System versions of Visual Studio 2008. If you have an Express Edition, Standard, or Professional you're out of luck.
Code Metrics 仅在 Visual Studio 2008 的 Team System 版本中可用。如果您有 Express Edition、Standard 或 Professional,那您就不走运了。
See comments and screenshots here:
在此处查看评论和屏幕截图:
回答by Lei
You don't need 3rd party tools, just press CTRL+SHIFT+F, and in the window that pops up choose "use regular expression". Use this Regular Expression:
你不需要第三者工具,只需按CTRL+ SHIFT+ F,在弹出的窗口中选择“使用正则表达式”。使用这个正则表达式:
^:b*[^:b#/]+.*$
For Visual Studio 2012and above the regular expression is:
对于 Visual Studio 2012及更高版本,正则表达式为:
^(?([^\r\n])\s)*[^\s+?/]+[^\n]*$
回答by Steve Dignan
DPack does this. After installing, just go to Tools -> DPack -> Solution Statistics...
DPack 就是这样做的。安装后,只需转到Tools -> DPack -> Solution Statistics..。
回答by Cyberherbalist
I don't have that feature in my VS2008, so a few months ago I implemented a quick and dirty windows app that counts the number of CRLFs in my C# files. Granted, this counts empty lines, and lines in files generated by VS, but with a bit of tweaking, I am sure you could make it generate a good count. Here is the operative code in the Windows Form; the dlgFolder control is the FolderBrowserDialog control:
我的 VS2008 中没有这个功能,所以几个月前我实现了一个快速而肮脏的 Windows 应用程序,它计算我的 C# 文件中的 CRLF 数量。当然,这会计算空行和由 VS 生成的文件中的行,但是通过一些调整,我相信你可以让它生成一个很好的计数。这是 Windows 窗体中的操作代码;dlgFolder 控件是 FolderBrowserDialog 控件:
if (dlgFolder.ShowDialog() == DialogResult.OK)
{
int totalLines = 0;
string[] fileList = Directory.GetFiles(dlgFolder.SelectedPath, "*.cs", SearchOption.AllDirectories);
for (int x = 0; x < fileList.Length; x++)
{
string[] sourceCodeLines = File.ReadAllLines(fileList[x]);
totalLines += sourceCodeLines.Length;
}
MessageBox.Show(String.Format("There are {0} lines of C# code in the folder{1}",
totalLines.ToString(), dlgFolder.SelectedPath));
}
回答by Javier
find . -type f -print0 | wc --files0-from=-
find . -type f -print0 | wc --files0-from=-
oops! you're on windows...
哎呀!你在窗户上...

