views:

13564

answers:

10

Hi,

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?

A: 

You could use:

Edward Wilde
LOX Metrics is very nice
Kovu
+26  A: 

An open source line counter for VS2005, 2003 and 2002 is available here:

http://www.wndtabs.com/

There is also discussion of creating a line counting VS addin, complete with code on Codeproject, here

http://www.codeproject.com/KB/macros/LineCounterAddin.aspx

Also Slick Edit Gadgets have a nice line-counter, here:

http://www.slickedit.com/content/view/441

and Microsoft Visual Studio Team System 2008 includes a good line counter.

Just remember though:

Measuring programming progress by lines of code is like measuring aircraft building progress by weight. Bill Gates

Ali Parr
+1 for Slick Edit Gadgets, its what I use (to satify my manager)
edosoft
Thanks for that, and don't worry the count is not a measure of programming progress!
Fermin
+1 for the quote! `:o>`
sbi
@sbi ditto! +1 to both of ya.
jonasespelita
Often counting lines of code is Just Plain Silly, and quantity does not imply quality. However, a huge team putting a 545,000 lb (545,000 lb!!) Dreamliner in the air is an entirely different accomplishment than launching the ultralite I built single handedly in my garage. And if you think about the number of lines of code in Windows, maybe Mr. Bill meant this in a different way than it is usually taken...?
mickeyf
+5  A: 

In Visual Studio Team System 2008 you can do from the menu Analyze--> 'Calculate Code Metrics for Solution' and it will give you a line count of your entire solution (among other things g)

SomeMiscGuy
Visual Studio Team System 2008 doesn't manage to count unmanaged code. ;)
Christian
+29  A: 

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

From a smallish solution's directory:

PS C:\Path> (dir -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> (dir -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? :)

Greg D
(The only time I've ever been asked to supply line counts was when upper management was figuring out how much time it would take to migrate all our products overseas so they could shut down our domestic site.)
Greg D
(Yes, this includes codegen'd files and comments. No, that doesn't bother me. Designers, gen'd code, and comments need to be maintained, too.)
Greg D
Thank you very much. Very nice and simple.
Tomas Pajonk
very nice, completely forgot about powershell. it should become default replacement for cmd
lubos hasko
Wow, pretty cool!
Andrew
Excellent! Your ending comment really sums it up, it's a trivial task, so why use a non-trivial tool? Though I really think it should be included in all versions of VS.
Sune Rievers
+5  A: 

cloc is an excellent commandline, Perl-based, Windows-executable which will break down the blank lines, commented lines, and source lines of code, grouped by file-formats.

Now it won't specifically run on a VS solution file, but it can recurse through directories, and you can set up filename filters as you see fit.

Here's the sample output from their web page:


prompt> cloc perl-5.10.0.tar.gz
    4076 text files.
    3883 unique files.                                          
    1521 files ignored.

http://cloc.sourceforge.net v 1.07  T=10.0 s (251.0 files/s, 84566.5 lines/s)
-------------------------------------------------------------------------------
Language          files     blank   comment      code    scale   3rd gen. equiv
-------------------------------------------------------------------------------
Perl               2052    110356    112521    309778 x   4.00 =     1239112.00
C                   135     18718     22862    140483 x   0.77 =      108171.91
C/C++ Header        147      7650     12093     44042 x   1.00 =       44042.00
Bourne Shell        116      3402      5789     36882 x   3.81 =      140520.42
Lisp                  1       684      2242      7515 x   1.25 =        9393.75
make                  7       498       473      2044 x   2.50 =        5110.00
C++                  10       312       277      2000 x   1.51 =        3020.00
XML                  26       231         0      1972 x   1.90 =        3746.80
yacc                  2       128        97      1549 x   1.51 =        2338.99
YAML                  2         2         0       489 x   0.90 =         440.10
DOS Batch            11        85        50       322 x   0.63 =         202.86
HTML                  1        19         2        98 x   1.90 =         186.20
-------------------------------------------------------------------------------
SUM:               2510    142085    156406    547174 x   2.84 =     1556285.03
-------------------------------------------------------------------------------

The third generation equivalent scale is a rough estimate of how much code it would take in a third generation language. Not terribly useful, but interesting anyway.

Mark Rushakoff
Very nice. Thanks!
James McNellis
+1 Works perfectly :)
Sune Rievers
+1  A: 

Other simple tool For VS2008 (open source): http://www.accendo.sk/Download/SourceStat.zip

LiborBes
+10  A: 

Found this tip: LOC with VS Find and replace

Not a plugin though if thats what you are looking for.

bobjink
worked nicely .
corymathews
Thank you, really nice one.
MartyIX
Perfect. Does a great job. +1
Liam
+2  A: 

A simple solution is to search in all files. Type in "*" while using wildcards. Which would match all lines. At the end of the find results window you should see a line of the sort:

Matching lines: 563 Matching files: 17 Total files searched: 17

Of course this is not very good for large projects, since all lines are mached and loaded into memory to be dispayed at the find results window.

Sogartar
+2  A: 

I prefer OxyProject Metrics VS Addin.

Heka
A: 

Try neptuner. It also gives you stuff like spaces, tabs, Lines of comments in addition to LoC. http://neptuner.googlecode.com/files/neptuner_0_30_windows.zip

sonofdelphi