如何在 Visual Studio 中显示我的项目包含多少行代码?

发布于 2024-07-18 04:43:13 字数 481 浏览 5 评论 0原文

可能的重复:
如何计算行数Visual Studio 解决方案中的代码?

如何在 Visual Studio 2008 Professional SP1 中显示代码指标窗口? 我想看看我的项目有多少行代码供学校使用,但我找不到。

帮助文件说要转到“查看”->“其他 Windows”->“代码指标”,但此选项对我不可用。 我还尝试右键单击解决方案资源管理器中的项目以查看是否有选项,但没有。

这个神秘的独角兽功能在哪里? 如果专业版没有此功能,是否有人找到了一种简单的外部方法来自动计算所有 .cs 文件中的行数?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

内心荒芜 2024-07-25 04:43:13

您不需要第 3 方工具,只需按 CTRL+SHIFT+F,然后在弹出的窗口中选择“使用正则表达式” ”。 使用此正则表达式:

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

对于 Visual Studio 2012 及更高版本,正则表达式为:

^(?([^\r\n])\s)*[^\s+?/]+[^\n]*$

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]*$
樱娆 2024-07-25 04:43:13

代码指标仅在 Visual Studio 2008 的 Team System 版本中可用。如果您有 Express Edition、Standard 或 Professional,那么您就不那么幸运了。

请参阅此处的评论和屏幕截图:

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:

酷遇一生 2024-07-25 04:43:13

DPack 就是这样做的。 安装后,只需进入工具-> DPack-> 解决方案统计...

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

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

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

平安喜乐 2024-07-25 04:43:13

我的 VS2008 中没有这个功能,所以几个月前我实现了一个快速但肮脏的 Windows 应用程序,用于计算 C# 文件中 CRLF 的数量。 当然,这会计算空行以及 VS 生成的文件中的行,但通过一些调整,我相信您可以使其生成良好的计数。 这是Windows窗体中的操作代码; dlgFolder 控件是FolderBrowserDialog 控件:

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));
}

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));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文