Quick tip: How to count the lines of code in a Visual Studio Solution?

Tuesday, July 25, 2017


Last night I was finishing my university project from one of the software engineering subject, and I was asking my self "How to count the lines of code in a Visual Studio Solution?"... I did not now how so I google it and find the very easy way to do that so I realized I can make a quick and short blog post about this solution. 😁

Just a quick quote from Bill Gates before this "tutorial".

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

... Anyway, to measure the LOC in Visual Studio I am using Visual Studio 2017 Community Edition, open you solution and right click on it and find Calculate Code Metrics.




After couple of second you will get the result, like this:


And that is it. Note that I have some issue with this .SAL project and I can not get result for it for some reason. This is my school project so it is not important for me.

Besides of number of lines of code (LOC) as you can see you will get info about:

  • Maintainablity Index
  • Cyclomatic Complexity
  • Depth of Inheritance
  • Class Coupling
  • and of course Lines Of Code (LOC)

As you can see steps are very simple. Right click on solution -> Calculate Code Metrics.

And just to "season" this very short blog post I will add the definitions for the terms from the list. 

Maintainability Index is a software metric which measures how maintainable (easy to support and change) the source code is. The maintainability index is calculated as a factored formula consisting of Lines Of Code, Cyclomatic Complexity and Halstead volume. From Wikipedia

Cyclomatic complexity is a software metric (measurement), used to indicate the complexity of a program. It is a quantitative measure of the number of linearly independent paths through a program's source code. From Wikipedia

Depth of inheritance, also called depth of inheritance tree (DIT), is defined as “the maximum length from the node to the root of the tree. From MSDN blogs.

Class coupling also goes by the name Coupling Between Objects (CBO) as originally defined by [CK94]. Basically, class coupling is a measure of how many classes a single class uses. A high number is bad and a low number is generally good with this metric. From MSDN blogs.



Sorry for the length of the blog post in the future it will be as usually but maybe sometimes in the future I will continue with this series of  "Quick tips".

If this was helpful for you, share it with the friends.

Best regards! Almir Vuk 

You Might Also Like

3 comments

  1. it seems to only work for c# code ...

    ReplyDelete
  2. This post was very, very brief... I was hoping to have some example code, I guess.

    ReplyDelete
  3. Why apologise Almir, your post is appreciated. It's short because it is precise, accurate and comprehensive. It addresses the question completely leaving nothing pending. Thank you so much.

    ReplyDelete