Quickly Count Number of Lines of Code in Your .Net Project

This new year holidays, my wife was busy working and getting ready for her IELTS exam, so there was no vacation. I took this chance to work on a project I have been dreaming about last year long.

The holidays are over and I have to go back to my daily job from monday, so I decided to count the number of lines I’ve been writing this christmas. This could give me in indication of how much fun I have these days. So I opened the powershell console and ran the following commands. My project doesn’t have much generated code, so I can say the results seem to be a rough estimate of reality.


cd \ProjectDirectory
$cs = ls -recurse -filter *.cs | gc | where {$_.Trim().Length -gt 5}
$sql = ls -recurse -filter *.sql | gc | where {$_.Trim().Length -gt 5}
$view = ls -recurse -filter *.cshtml | gc | where {$_.Trim().Length -gt 5}
$cs.Count + $sql.Count + $view.Count

1,234,980

Of course the above number is just a joke. I couldn’t possibly write a million lines in a couple of weeks even if I’ve had my keyboard connected to the treadmill!

Wish you all a successful and merry 2013.