nmbl Documentation
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage
Edit page

loc - Lines of Code

Overview

The loc command counts lines of code in your .NET projects and solutions. It produces a breakdown of total lines, logical lines of code, blank lines, comment lines, and brace-only lines, followed by a list of the top 10 largest files by logical LOC.

When a directory is provided and it contains exactly one .slnx solution file, all projects in that solution are analyzed. Otherwise the path is treated as a .csproj file or a plain directory.

Syntax

nmbl loc <ProjectOrSolutionPath> [--exclude-generated]

Arguments

  • ProjectOrSolutionPath - Path to a .csproj file, a .slnx solution file, a project directory, or . for the current directory.
  • --exclude-generated (optional) - Exclude common auto-generated files such as *.Designer.cs, *.g.cs, and *.AssemblyInfo.cs.

Output

Prints a summary box followed by a top-10 files table.

Analyzing 42 C# file(s)...

╔══════════════════════════════════════════════════════════════╗
║                   LINES OF CODE SUMMARY                      ║
╠══════════════════════════════════════════════════════════════╣
║  Files Analyzed:              42                             ║
║  Total Lines:              4,821                             ║
║  Logical Lines (LOC):      3,104                             ║
║  Blank Lines:                612                             ║
║  Comment Lines:              389                             ║
║  Brace-Only Lines:           716                             ║
╚══════════════════════════════════════════════════════════════╝

Top 10 files by logical lines of code:

File                                                              LOC    Total
------------------------------------------------------------------------------
src/Services/OrderService.cs                                      312      418
src/Controllers/OrdersController.cs                               187      241

Line categories

  • Total Lines — every line in the file, including blank lines and comments.
  • Logical Lines (LOC) — lines that contain executable code, excluding blanks, comments, and brace-only lines. This is the primary size metric.
  • Blank Lines — empty or whitespace-only lines.
  • Comment Lines — lines consisting entirely of a comment.
  • Brace-Only Lines — lines containing only { or }.

Exit Codes

  • 0 - Success, including when no C# files are found.
  • 1 - The required path argument is missing or an unexpected error occurs.

Examples

Count lines in a project

nmbl loc src/MyProject/MyProject.csproj

Count lines in a solution

nmbl loc MySolution.slnx

Counts lines across all projects in the solution.

Count lines in the current directory

nmbl loc .

If the current directory contains exactly one .slnx file, the solution is analyzed. Otherwise all C# files in the directory tree are analyzed.

Exclude auto-generated files

nmbl loc . --exclude-generated

Use this option to skip common generated files (for example, Foo.Designer.cs) so the metrics focus on hand-written code.

Track growth over time

# Capture a baseline
nmbl loc MySolution.slnx > metrics/loc-baseline.txt

# After development, capture again
nmbl loc MySolution.slnx > metrics/loc-current.txt

Measure specific layers

nmbl loc src/Core/Core.csproj
nmbl loc src/Infrastructure/Infrastructure.csproj
nmbl loc src/Web/Web.csproj

Compare the relative sizes of different architectural layers.

Tips

Combine with other metrics

nmbl loc MySolution.slnx
nmbl cc MySolution.slnx
nmbl cogc MySolution.slnx
nmbl regions MySolution.slnx
nmbl todos MySolution.slnx

Include in CI artifacts

nmbl loc MySolution.slnx | tee build-artifacts/loc-report.txt
  • cc - Calculate cyclomatic complexity
  • cogc - Calculate cognitive complexity
  • todos - Find TODO comments