Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 217
Fermin Avatar asked Aug 07 '09 13:08

Fermin


People also ask

How do I count line codes in Visual Studio?

In VS2010 there is a in-built tool that counts all lines of code and other values too: Go to View -> Other Windows -> Code metrics results. A little button in the corner that looks like a calendar, click that, the tooltip should say Calculate code metrics for soulution, and let VS do it's thing.

How do you calculate the number of lines of code?

Take one of your existing project, get the number of lines and divide it by the time it took you to code it. This will give you a kind of lines per hour metric. Then, try to estimate how many time you have worked with that specific language and multiply it with your already calculated metric.


1 Answers

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? :)

like image 148
Greg D Avatar answered Oct 09 '22 11:10

Greg D