How do you count the lines of code in a Visual Stu

2019-01-03 11:28发布

Is it possible to find the number of lines of code in an entire solution? I've heard of MZ-Tools, but is there an open source equivalent?

25条回答
来,给爷笑一个
2楼-- · 2019-01-03 11:47

Visual Studio 2010 Ultimate has this built-in.

Analyze -> Calculate Code Metrics

查看更多
神经病院院长
3楼-- · 2019-01-03 11:48

Regular expressions have changed between VS2010 and 2012, so most of the regular expression solutions here no longer work

(^(?!(\s*//.+)))+(^(?!(#.+)))+(^(?!(\s*\{.+)))+(^(?!(\s*\}.+)))+(^(?!(\s*\r?$)))+

Will find all lines that are not blank, are not just a single bracket ( '{' or '}' ) and not just a #include or other preprocessor.

Use Ctrl-shift-f and make sure regular expressions are enabled.

The corresponding regular expression for VS 2010 and older is

^~(:Wh@//.+)~(:Wh@\{:Wh@)~(:Wh@\}:Wh@)~(:Wh@/#).+
查看更多
等我变得足够好
4楼-- · 2019-01-03 11:49

You can use the Visual Studio Code Metrics PowerTool 10.0. It's a command-line utility that calculates a few metrics on managed code for you (including lines of code). You can get a VS 2010 plugin that brings the tool into Visual Studio, and makes it as quick as selecting the menu item and clicking "Analyze Solution."

查看更多
Lonely孤独者°
5楼-- · 2019-01-03 11:50

For future readers I'd like to advise the DPack extension for Visual Studio 2010.

It's got a load of utilities built in including a line counter which says how many lines are blank, code, and etc.

查看更多
戒情不戒烟
6楼-- · 2019-01-03 11:50

A simple solution is to search in all files. Type in "*" while using wildcards. Which would match all lines. At the end of the find results window you should see a line of the sort:

Matching lines: 563 Matching files: 17 Total files searched: 17

Of course this is not very good for large projects, since all lines are mached and loaded into memory to be dispayed at the find results window.

Reference:

查看更多
来,给爷笑一个
7楼-- · 2019-01-03 11:50

I prefer OxyProject Metrics VS Addin.

查看更多
登录 后发表回答