7

I'm unable to find a good option for my Visual Studio 2017.

I tried right clicking the projects, but there wasn't an option for "Analyze".

Just a few hours ago, I installed "Roslyn Code Analysis" using Nuget package manager. It's installed as "Archimetrics.Analysis".

How do I get "Lines of code" using this package. I have tried all the tried all the common ways of right clicking and trying to fins something but to no avail. That's why I installed this package "Roslyn" for code analysis, which is installed as "Archimetrics.Analysis".

Vivek Jaiswal
  • 97
  • 1
  • 1
  • 3
  • Did you find any solution? I did find how to do a LOC count, but it doesn't count any JavaScript unfortunately – Michel May 15 '18 at 07:03

3 Answers3

22

A little hacky way that works quite well is to use a RegEx with Find in Files

  1. Ctrl-Shift-F or Edit -> Find and Replace -> Find in Files
  2. Use ^(?([^\r\n])\s)*[^\s+?/]+[^\n]*$ in the 'Find what:' field
  3. Check 'Use Regular Expressions'
  4. Set 'Look in:' and 'Look at these file types:' to your desired search scope
  5. Hit enter and scroll to the bottom after the find is complete and you'll see Matching lines: 25843. That's the line count
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
sam
  • 542
  • 5
  • 11
11

I use the famous "Supercharger" extension and among the many functions,it has just that:

Supercharger

Result:


Code structure statistics for project 'SysMonitor_1'

C# classes        :        14
C# interfaces     :         1
C# structs        :         1
C# enums          :         0

C# functions      :        49
C# properties     :        11

Code line count statistics for project 'SysMonitor_1'

C# comment lines  :       128
C# empty lines    :       105
C# pure code lines:       722
-----------------------------
Total C# lines    :       955

Non-C# lines      :       607

=============================
All lines         :     1.562
Brummell
  • 211
  • 2
  • 17
  • This is very good, but I'll just mention that it isn't free, although there is a 30-day free trial period. http://supercharger.tools/ – RenniePet Feb 04 '18 at 12:07
  • @RenniePet there is "Community License" and is free, if not commercial use: http://supercharger.tools/pricing.html – Brummell Feb 04 '18 at 21:17
11

You can use the Analyze -> Calculate Code Metrics -> For Solution option.

It will calculate the Maintainability Index, Cyclomatic Complexity, Depth of Inheritance, Class Coupling and Lines of Code.

Visual Studio 2017 Analyze Menu Calculate Code Metrics Option

Code Metrics Result

For Further Details, you can consult the documentation at: Measure code maintainability with code metrics

melleck
  • 306
  • 4
  • 15