StyleCop was just released!

How To Count Lines of Code in Visual Studio

22. November 2011 02:00 by Scott in Visual Studio, Tricks  //  Tags: , , ,   //   Comments (0)

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


If your like me, then you want to know at times how many lines of code you have written over the years.  I have this one web site that I thought would be roughly 200,000 lines of code.  Its over at  I questioned today how many lines of code I have when I was in discussion with one of my coworkers.  He didn’t think that my website offered that much and well, I had to prove him wrong.  So in figuring out how many lines of code I wrote, I had two different ways.  Here are the ways.

When using Visual Studio Team System:

Analyze -> Calculate Code Metrics has the ability to count projects of code, but not actually web forms applications.  The problem with this, is that I actually have a website and not an actual C# project, So I used the second method.

Visual Studio Trick:

This method will will match every line that are not comments (//), a compiler directive (starts with #), a single opening or closing brace, or blank lines. So these are true lines of code.

  • Select Edit -> Find & Replace -> Find in files… or just press CTRL+SHIFT+F
  • Check Use and select Regular expressions.
  • Top Left Drop down using the Find in Files Selection
  • Type the following as the text to find:

for C#


for VB.NET (thanks Steve for the info!)



  • If you select Current project or Entire solution, you also need to specify the file types that will be included in the search.

Proceed with the “search” and at the bottom of the Find results window you will see the total line count.