Rich Newman

July 9, 2007

C#, Visual Basic and C++ .NET Line Counter Utility – Version 2

Filed under: .net, c#, dotnet, line count, line counter, technology, utility — richnewman @ 10:09 pm

Downloads

Source code download.

Executable download.

Update

An updated version of the line count utility described in an earlier article is now available. This now:

  • Does basic C++ line counting of Visual Studio.NET projects and solutions, as well as C# and VB.NET as previously.
  • Counts the total number of code files and displays them in the summary section.
  • Allows the summary to be selected (by dragging over it) and copied to the clipboard with Ctrl-C.

Unfortunately for C++ projects I don’t think there’s an easy way of identifying auto-generated code, and hence the application will always return zero for code-generated lines for C++ projects.

Code Project

An abbreviated version of these articles is available on the Code Project.

Advertisements

30 Comments »

  1. Rich, the .zip file for the executable seems to be corrupted (source is OK).

    Comment by David Brabant — July 10, 2007 @ 12:46 pm

  2. David

    It’s working fine for me. What problem are you seeing?

    Comment by richnewman — July 10, 2007 @ 7:32 pm

  3. Zip file is def corrupted.

    Comment by Anonymous — August 2, 2007 @ 12:55 pm

  4. Guys

    I have rebuilt the executable and reposted the zip. I think it should be OK now.

    Rich

    Comment by richnewman — August 4, 2007 @ 4:29 pm

  5. Thx This Works Great!

    Comment by Johann Combrink — August 17, 2007 @ 9:56 am

  6. Hi Rich,

    I found this via the Code Project.

    I’m trying to generate useful information about Lines of Code during the build process. I can’t tell from the articles if there is a command line option or a non-interactive (html/xml) output option. Have you considered using such?

    Comment by Michael Croft — September 18, 2007 @ 9:52 pm

  7. Hi!
    Thank you for the great utility. When I am analysing a vb.net 2003 project, I get the following error message in FindCodeFilesAndAddToChildContainersList: Invalid character in xml.
    The reason is, that a filename in my *.proj contains a german umlaut (Ü), which is not XML-conform. Do you know a quick workaround?

    Thanks!
    Tobias

    Comment by Tobias Schittkowski — October 16, 2007 @ 7:50 am

  8. Great little utility, just what i was looking for. cheers.

    Comment by Tom — November 21, 2007 @ 11:30 pm

  9. Hi Rich,

    Thanks for a great tool. I have one question, I tried it on a web service project (2005) and it did not pick up the program files in the app_code folder. Is there a setting that I can make to have it do that?

    Thanks,
    John

    Comment by John Hosier — March 3, 2008 @ 5:03 pm

  10. You rock.

    Thanks,
    Stephen and Andy

    Comment by RabidWoo — March 26, 2008 @ 2:46 am

  11. Wow,

    Much thanks for the software. 🙂
    Any chance of adding a print to screen option? so i could save it as a picture (jpeg, gif, bmp, etc)?

    Much thanks anyway
    Tzach

    Comment by Tzach Solomon — June 9, 2008 @ 10:53 pm

  12. This tool is very useful for my MSE project 🙂
    Thanks a lot

    Comment by Aghsan — June 19, 2008 @ 1:25 am

  13. Very helpfull ! Thanx a lot!!!!

    Comment by Alex. Tz. — June 28, 2008 @ 12:02 pm

  14. Hi,

    I found your application extremely useful. I made a couple of modifications to it if you are interested.

    We use a lot of codeSmith templates in our projects so I wanted to to take the templates, and generated code into consideration. I also wanted to process .dbp prjoject (database projects).

    I modified the code to handle .dbp, .sql, and .cst (code smith template) files and it seems to work fine. I had to modify the dataset, add some counters, etc. I also updated it to 3.5 of the framework and use some Linq stuff for array processing and the like.

    If you are interested in the changes let me know and I can zip and get them to you.

    Thanks again for this head start, your code was easy to read and modify and was a pleasure to work with.

    Thanks,
    Jeff

    Comment by Jeff Marino — August 6, 2008 @ 7:37 pm

  15. Nice Tool.Found your tool after a long search in web

    Comment by Anonymous — September 2, 2008 @ 8:06 am

  16. I was looking for a way to count lines in a large web application that I developed at work, and found this. It didn’t quite work for me out of the box (.NET Web Projects don’t have project files so this utility only found and counted my Helpers code, which is compiled in it’s own proj file to a DLL). However with the great documentation and design of the application I was able to modify the project in about an hour to do exactly what I wanted.

    Thanks for the great utility, and for making it open-source so I could make it work for me too!

    PS: If you want the code to make it work with Web Projects shoot me an email, I’d be happy to send it over. I did it with very minor changes to the CodeContainer and Factory classes and adding some items to the interface, all of which were needed to allow the utility to count based on Directory and added a class (called WebProject) which inherits and implements CodeContainer.

    Comment by Ryan A — September 2, 2008 @ 6:26 pm

  17. […] Oh ya, tool Line Counter buatan mas Rich Newman ini bisa di-download disini. […]

    Pingback by 4,828 baris kode, Win32, dan pelajaran tentang Multi-Threading di Single-Threaded Apartment (STA) - Z & his Startup — September 27, 2008 @ 8:21 am

  18. thnx for this great tool… if you just want to use it for counting lines etc. it is even better then code metric in vs.

    Comment by jayan — October 7, 2008 @ 6:38 am

  19. A suggestion would be to show the raw C# line count, this is what I neeed.

    Comment by Glenn — December 4, 2008 @ 5:27 pm

  20. Thanks for the tool. It works well. Curious, why is it so big (>60MB)?

    Comment by Steve — January 17, 2009 @ 5:55 pm

  21. Thanks! Very quick and useful.

    Comment by Mark Stahler — February 2, 2009 @ 5:09 am

  22. Thanks! This is quite useful.

    One great feature would be the ability to export the data generated to various formats – e.g., .xls, .html, etc.

    Comment by Anonymous — February 8, 2009 @ 7:28 am

  23. Thanks.

    Comment by Jef Claes — May 13, 2009 @ 10:46 am

  24. Great work Rich! Really helped me. 🙂

    Comment by Fariha Akhtar — May 14, 2009 @ 8:46 am

  25. I use LineCount to count lines in C++ files based on .NET Solution. I found out that all files with relative path (i.e. ..\..\filename) has 0 lines
    Why ?

    Comment by Shlomit — May 25, 2010 @ 9:40 am

    • I had this same problem so I downloaded the source code, and took a look.
      Anyway, I fixed the ..\..\ by doing the following (no guarantees about fixing or breaking other relative paths though):

      Open the Project.cs file in the CodeContainers folder.
      Look for the AddCodeFileToList function (line 69 in mine).

      Locate the following line of code in the function (line 73 in mine):
      if (codeFileRelativeName.StartsWith(“.”)) codeFileRelativeName = codeFileRelativeName.Substring(2);

      Comment this line out, ie:
      //if (codeFileRelativeName.StartsWith(“.”)) codeFileRelativeName = codeFileRelativeName.Substring(2);

      Or replace it with:
      if (codeFileRelativeName.StartsWith(“.\\”)) codeFileRelativeName = codeFileRelativeName.Substring(2);

      After I did this, all paths with ..\..\ loaded correctly.
      The reason this was breaking was because the path was being changed from something like “..\\..\\SomeFileName.cs” to “\\..\\SomeFileName.cs”

      Anyway, it ‘should’ be fairly safe to comment the line out as the ‘Path.Combine’ function seems to be intelligent enough to handle relative paths (at least on mine it does).

      The 2nd alternative basically checks to see if the path starts with .\ and omits it, but leaves paths with ..\ alone.

      Comment by David — November 10, 2010 @ 8:27 pm

  26. Thank you very much for this, Rich.

    I have made the necessary changes so it also works with Visual Studio 2010 C++ projects. Email me at “email at rennie-petersen dot eu” if you’d like me to send these changes to you.

    Comment by renniepet — December 22, 2010 @ 9:50 am

  27. Very handy – ideal for situations where you don’t have (or wan’t) nDepend installed. Many thanks.

    Comment by Steve Dunn — April 10, 2011 @ 4:28 pm

  28. how to line let’s get rich hack tool

    C#, Visual Basic and C++ .NET Line Counter Utility – Version 2 | Rich Newman

    Trackback by how to line let's get rich hack tool — January 7, 2015 @ 5:01 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: