How to Count the Lines of Code (LOC) in your application using Visual Studio

I was talking to someone the other day and he asked me whether Visual Studio has a tool to count the lines of code in an application. It occurred to me that others might be interested in the answer so I decided to blog about it.

There is a tool called Code Metrics in Visual Studio 2008 and 2010 that among other things, counts the lines of code in a project. Using Code Metrics is very simple. In Solution Explorer, select the project that you want to know the LOC for, right-click and select "Calculate Code Metrics".

The screenshot below shows the Code Metrics window. One of the nice things about the Code Metrics window is that it shows you the lines of code per project, namespace, class or method.


Habib Heydarian.

Comments (2)

  1. vandanachadha says:

    My question is more related to the other post of creating Rule sets in VS 2010 IDE (where comments are disabled). I am using VS2010 Professional Beta 2 version (10.0.21006.1), but there does not exist any option for "Code Analysis" in the Project Properties. Is this option available only for Premium and Team versions?

  2. Yes, Code Analysis is only available in the Premium and above editions.

Skip to main content