loc - Lines of Code
Overview
The loc command counts lines of code in your .NET projects and solutions. It provides accurate line counts for C# source files, helping you measure project size and track growth over time.
Syntax
nmbl loc <ProjectOrSolution>Arguments
ProjectOrSolution- Path to a .csproj or .slnx file
Output
Displays line counts for each file and provides totals, helping you understand the size and distribution of your codebase.
Examples
Count Lines in a Project
nmbl loc src/MyProject/MyProject.csprojShows line counts for all C# files in the specified project.
Count Lines in a Solution
nmbl loc MySolution.slnxCounts lines across all projects in the solution.
Track Growth Over Time
# Create a baseline
nmbl loc MySolution.slnx > metrics/loc-baseline.txt
# After development
nmbl loc MySolution.slnx > metrics/loc-current.txt
# Compare the files to see growthMeasure Specific Components
nmbl loc src/Core/Core.csproj
nmbl loc src/Infrastructure/Infrastructure.csproj
nmbl loc src/Web/Web.csprojCompare sizes of different components in your architecture.
Understanding the Results
The line count includes:
- All lines in C# source files (.cs)
- Includes comments, blank lines, and code
This metric can help you:
- Estimate effort - Larger codebases typically require more maintenance
- Track growth - Monitor how your codebase evolves
- Identify large files - Find files that might benefit from splitting
- Compare components - Understand the relative size of different parts
Tips
Combine with Other Metrics
# Get comprehensive metrics
nmbl loc MySolution.slnx
nmbl cc MySolution.slnx
nmbl cogc MySolution.slnx
nmbl regions MySolution.slnx
nmbl todos MySolution.slnxAutomation
# Add to CI/CD pipeline
nmbl loc MySolution.slnx | tee build-artifacts/loc-report.txtInclude line count reports in your build artifacts.
Related Commands
Next
iterate