Cherry Wu
Cherry Wu

Reputation: 4074

Visual Studio 2012 Ultimate: count code lines in Team Explorer

I know we can use code metrics to count code lines of the whole project, but my source code from Team Explorer, when I use code metrics, it jumps to Solution Explorer. I tried to move all my files to a blank solution, but cannot move/

So, my question is: 1. Is there any way to copy all my folders and files to my blank solution? 2. Can we use code metrics or any other tools to count the code lines in Team Explorer in Visual Studio 2012?

Upvotes: 2

Views: 254

Answers (1)

outcoldman
outcoldman

Reputation: 11832

You don't really need special Visual Studio feature for this. You can just download this project and launch next command in PowerShell:

ls *.cs -r | sls . | wc -l

Just open PowerShell console, go to the root folder where if your project located and launch this command. It will find all cs files (recursive) select all lines and count the lines in these files.

This command in details:

  1. ls *.cs -r - get all files recursive from current folder (ls is an alias for Get-Children)

  2. | - move results to next command (pipeline)

  3. sls . select all string from file (sls is alias for Select-String). So for each file it gets from ls command it will select all lines. You can use regular expression to select what kind of lines you want to get, for example you can write something like select-string "^.*[^\s].*$" to select only not-empty lines.

  4. After one more pipeline we are asking to just count lines with wc (this is alias for Measure-Object).

You can read more details on each command to do something special (to count words with wc for example).

Upvotes: 3

Related Questions