[visual-studio] How do you count the lines of code in a Visual Studio solution?

Here's an update for Visual Studio 2012/2013/2015 for those who want to do the "Find" option (which I find to be the easiest): This RegEx will find all non-blank lines with several exclusions to give the most accurate results.

Enter the following RegEx into the "Find" box. Please make sure to select the "Use Regular Expressions" option. Change the search option to either "Current Project" or "Entire Solution" depending on your needs. Now select "Find All". At the bottom of the Find Results window, you will see "Matching Lines" which is the lines of code count.


^(?!(\s*\*))(?!(\s*\-\-\>))(?!(\s*\<\!\-\-))(?!(\s*\n))(?!(\s*\*\/))(?!(\s*\/\*))(?!(\s*\/\/\/))(?!(\s*\/\/))(?!(\s*\}))(?!(\s*\{))(?!(\s(using))).*$

This RegEx excludes the following items:


Comments

// This is a comment

Multi-Line comments (assuming the lines are correctly commented with a * in front of each line)

/* I am a
* multi-line
* comment */

XML for Intellisense

/// <summary>
/// I'm a class description for Intellisense
/// </summary>

HTML Comments:

<!-- I am a HTML Comment -->

Using statements:

using System;
using System.Web;

Opening curly braces:

{

Closing curly braces:

}

Note: anything between the braces would be included in the search, but in this example only 4 lines of code would count, instead of 18 actual non-blank lines:

        public class Test
        {
            /// <summary>
            /// Do Stuff
            /// </summary>
            public Test()
            {
                TestMe();
            }
            public void TestMe()
            {
                //Do Stuff Here
                /* And
                 * Do
                 * Stuff
                 * Here */
            }
        }

I created this to give me a much more accurate LOC count than some previous options, and figured I would share. The bosses love LOC counts, so I'm stuck with it for a while. I hope someone else can find this helpful, let me know if you have any questions or need help getting it to work.