How do you count the lines of code in a Visual Studio solution?

Is it possible to find the number of lines of code in an entire solution? I've heard of MZ-Tools, but is there an open source equivalent?


Visual Studio 2010 Ultimate has this built-in.

Analyze -> Calculate Code Metrics


I've found powershell useful for this. I consider LoC to be a pretty bogus metric anyway, so I don't believe anything more formal should be required.

From a smallish solution's directory:

PS C:Path> (gci -include *.cs,*.xaml -recurse | select-string .).Count
8396
PS C:Path>

That will count the non-blank lines in all the solution's .cs and .xaml files. For a larger project, I just used a different extension list:

PS C:Other> (gci -include *.cs,*.cpp,*.h,*.idl,*.asmx -recurse | select-string .).Count
909402
PS C:Other>

Why use an entire app when a single command-line will do it? :)


I used Ctrl+Shift+F. Next, put a n in the search box and enable regular expressions box. Then in the find results, in the end of the screen are the number of files searched and lines of code found.

链接地址: http://www.djcxy.com/p/59686.html

上一篇: 将外键添加到现有表

下一篇: 你如何计算Visual Studio解决方案中的代码行数?