How do I show how many lines of code my project contains in Visual Studio? [duplicate]
Asked Answered
E

4

22

Possible Duplicate:
How do you count the lines of code in a Visual Studio solution?

How can I show the code metrics window in Visual Studio 2008 Professional SP1? I'm looking to see how many total lines of code my project is for school and I can't find it.

The help file said to go to View->Other Windows->Code Metrics, but this option is not available to me. I also tried right-clicking the project in the Solution Explorer to see if there was an option but there wasn't.

Where is this mythical unicorn of a feature? If the Pro version doesn't have this feature has anyone found a simple external method to count the lines in all .cs files in an automated way?

Estafette answered 5/5, 2009 at 22:8 Comment(1)
See here: #1245229 Has an even better and more flexible powershell command then Javier has available to him in unix.Seldan
A
11

Code Metrics is only available in the Team System versions of Visual Studio 2008. If you have an Express Edition, Standard, or Professional you're out of luck.

See comments and screenshots here:

Ahrens answered 5/5, 2009 at 22:17 Comment(2)
More recent versions of Visual Studio (in my case, 2013) now include it at the Professional level.Lecythus
In Community 2015 version this great option exist.Kozlowski
U
126

You don't need 3rd party tools, just press CTRL+SHIFT+F, and in the window that pops up choose "use regular expression". Use this Regular Expression:

^:b*[^:b#/]+.*$

For Visual Studio 2012 and above the regular expression is:

^(?([^\r\n])\s)*[^\s+?/]+[^\n]*$
Unworldly answered 6/1, 2010 at 16:15 Comment(5)
Nice! That is a pretty cool solution to a common problem. I used to use DPack but I found it interfered with R# etc too much. +1Caveator
Does anyone know if this still works in VS2012? sounds like a neat trickWynn
For VS2012 (as far as they changed Regex syntax) it will be: ^(?([^\r\n])\s)*[^\s+?/]+[^\n]*$Ptolemaist
VS 2013 has a great option... Go to Analyze tab and Click Calculate Code Metrics for Solution.Loathing
How does this regex differ from just using \n?Baggy
A
11

Code Metrics is only available in the Team System versions of Visual Studio 2008. If you have an Express Edition, Standard, or Professional you're out of luck.

See comments and screenshots here:

Ahrens answered 5/5, 2009 at 22:17 Comment(2)
More recent versions of Visual Studio (in my case, 2013) now include it at the Professional level.Lecythus
In Community 2015 version this great option exist.Kozlowski
A
8

DPack does this. After installing, just go to Tools -> DPack -> Solution Statistics...

http://www.usysware.com/dpack/

Acidulant answered 5/5, 2009 at 22:26 Comment(0)
L
2

I don't have that feature in my VS2008, so a few months ago I implemented a quick and dirty windows app that counts the number of CRLFs in my C# files. Granted, this counts empty lines, and lines in files generated by VS, but with a bit of tweaking, I am sure you could make it generate a good count. Here is the operative code in the Windows Form; the dlgFolder control is the FolderBrowserDialog control:

if (dlgFolder.ShowDialog() == DialogResult.OK)
{
   int totalLines = 0;
   string[] fileList = Directory.GetFiles(dlgFolder.SelectedPath, "*.cs",    SearchOption.AllDirectories);

   for (int x = 0; x < fileList.Length; x++)
   {
      string[] sourceCodeLines = File.ReadAllLines(fileList[x]);
      totalLines += sourceCodeLines.Length;    
   }

   MessageBox.Show(String.Format("There are {0} lines of C# code in the folder{1}",
totalLines.ToString(), dlgFolder.SelectedPath));
}
Loppy answered 5/5, 2009 at 23:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.