Number of lines in code [closed]
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this questionIs there a tool or something else to count the number of lines in a specific C# project? Just out of curiosity...
I believe there are tools, but I find it easier to just use the Find in Files option and use this regex:
^~(:Wh@//.+)~(:Wh@\{:Wh@)~(:Wh@\}:Wh@)~(:Wh@/#).+
That regex is from here, which also shows how to search for it. It will return a number of matching lines (i.e. the number of lines in your code)
In Visual Studio 2010 Premium and Ultimate, you can go to the Analyze tab and select "Calculate Code Metrics", it gives you lines of code as well as a maintainability index, cyclomatic complexity, depth of inheritance and class coupling metrics, project by project.
You can drill into namespaces and classes/interfaces as well.
Visual Studio does that if you use its "Code Analysis" tool.
Edit: a 10-second google search (with the terms sloc count c#) returns this Code Project article: http://www.codeproject.com/KB/files/directorylinecounter.aspx
I've had good success with David Wheeler's SLOCCount. It's a command line tool, which will require Cygwin unfortunately, but I found it handled very large Java projects without fuss. C# is listed as a supported language for counting. Configuration is minimal, IIRC I just pointed it at a directory and it summarised all the type of code and broke it down in lines per language.
Highly recommended.
精彩评论