Joan Venge Joan Venge - 1 month ago 13
C# Question

How to count the number of code lines in a C# solution, without comments and empty lines, and other redundant stuff, etc?

By redundant stuff, I mean the namespaces, as I know they are necessary but if there are 10k of them, it doesn't add valuable info to the table.

Could this be done using Linq?

Answer

No need to reinvent the wheel. Take a look at the Visual Studio Code Metrics PowerTool 11.0

Overview

The Code Metrics PowerTool is a command line utility that calculates code metrics for your managed code and saves them to an XML file. This tool enables teams to collect and report code metrics as part of their build process. The code metrics calculated are:

• Maintainability Index

• Cyclomatic Complexity

• Depth of Inheritance

• Class Coupling

• Lines Of Code (LOC)

I know you said you don't have Ultimate, so I just wanted to show you what you're missing.

Code Metrics in VS 2010 Ultimate

For everyone else, there's SourceMonitor Source Monitor