是否有可能找到整个解决方案中的代码行数?我听说过MZ-Tools,但是是否有一个开源的工具?
当前回答
显然工具更容易,但我觉得在powershell这样做很酷:)
该脚本查找.sln文件中的所有.csproj引用,然后在每个csproj文件中查找包含用于编译的文件。对于包含用于编译的每个文件,它都会创建一个具有以下属性的对象:解决方案、项目、文件、行。它将所有这些对象存储在一个列表中,然后根据需要对数据进行分组和投影。
#path to the solution file e.g. "D:\Code\Test.sln"
$slnFile = "D:\Code\Test.sln"
#results
$results = @()
#iterate through .csproj references in solution file
foreach($projLines in get-item $slnFile | Get-Content | Select-String '".*csproj')
{
$projFile = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($slnFile), [regex]::Match($projLines,'[^"]*csproj').Value)
$projFolder = [System.IO.Path]::GetDirectoryName($projFile)
#from csproj file: get lines for files to compile <Compile Include="..."/>
$includeLines = get-item $projFile | Get-Content | Select-String '<Compile Include'
#count of all files lines in project
$linesInProject = 0;
foreach($fileLine in $includeLines)
{
$includedFilePath = [System.IO.Path]::Combine($projFolder, [Regex]::Match($fileLine, '"(?<file>.*)"').Groups["file"].Value)
$lineCountInFile = (Get-Content $includedFilePath).Count
$results+=New-Object PSObject -Property @{ Solution=$slnFile ;Project=$projFile; File=$includedFilePath; Lines=$lineCountInFile }
}
}
#filter out any files we dont need
$results = $results | ?{!($_.File -match "Designer")}
#print out:
"---------------lines per solution--------------"
$results | group Solution | %{$_.Name + ": " + ($_.Group | Measure-Object Lines -Sum).Sum}
"---------------lines per peoject--------------"
$results | group Project | %{$_.Name + ": " + ($_.Group | Measure-Object Lines -Sum).Sum}
其他回答
我更喜欢OxyProject Metrics VS插件。
VS2005, 2003和2002的开源行计数器可以在这里找到:
http://www.wndtabs.com/
这里还讨论了如何创建行计数VS插件,并在Codeproject中提供了完整的代码
http://www.codeproject.com/KB/macros/LineCounterAddin.aspx
另外,Slick Edit Gadgets有一个不错的行计数器,这里:
http://www.slickedit.com/products/slickedit
和Microsoft Visual Studio Team System 2008包括一个很好的行计数器。
不过要记住:
用代码行数来衡量编程进度就像用重量来衡量飞机制造进度。 比尔盖茨
你可以用:
SCLOCCount http://www.dwheeler.com/sloccount/-开源 Loc度量,http://www.locmetrics.com/ -不是开源的,但是很容易使用
这里的答案有点过时了,可能是从2008年开始的。因为在较新的Visual Studio版本2010/2012中,此功能已经内置。因此,没有理由为它使用任何扩展或工具。
计算代码行数的功能-计算度量。有了它,您可以计算每个项目或解决方案的度量(LOC、维护索引、圈索引、继承深度)。
只需在解决方案资源管理器中右键单击解决方案或项目,
并选择“计算指标”
以后用于分析和聚合的数据可以导入到Excel中。此外,在Excel中,你还可以过滤掉生成的类或其他指标中的杂音。包括代码行LOC在内的这些指标也可以在构建过程中收集,并包含在构建报告中
cloc是一个优秀的命令行、基于perl的windows可执行文件,它将按文件格式分组,分解空行、注释行和源代码行。
现在它不会专门运行在VS解决方案文件上,但它可以递归遍历目录,并且您可以根据需要设置文件名过滤器。
以下是他们网页上的输出示例:
prompt> cloc perl-5.10.0.tar.gz 4076 text files. 3883 unique files. 1521 files ignored. http://cloc.sourceforge.net v 1.07 T=10.0 s (251.0 files/s, 84566.5 lines/s) ------------------------------------------------------------------------------- Language files blank comment code scale 3rd gen. equiv ------------------------------------------------------------------------------- Perl 2052 110356 112521 309778 x 4.00 = 1239112.00 C 135 18718 22862 140483 x 0.77 = 108171.91 C/C++ Header 147 7650 12093 44042 x 1.00 = 44042.00 Bourne Shell 116 3402 5789 36882 x 3.81 = 140520.42 Lisp 1 684 2242 7515 x 1.25 = 9393.75 make 7 498 473 2044 x 2.50 = 5110.00 C++ 10 312 277 2000 x 1.51 = 3020.00 XML 26 231 0 1972 x 1.90 = 3746.80 yacc 2 128 97 1549 x 1.51 = 2338.99 YAML 2 2 0 489 x 0.90 = 440.10 DOS Batch 11 85 50 322 x 0.63 = 202.86 HTML 1 19 2 98 x 1.90 = 186.20 ------------------------------------------------------------------------------- SUM: 2510 142085 156406 547174 x 2.84 = 1556285.03 -------------------------------------------------------------------------------
第三代等效规模是对第三代语言需要多少代码的粗略估计。不是特别有用,但是很有趣。
推荐文章
- 如何为构造函数定制Visual Studio的私有字段生成快捷方式?
- 为什么Visual Studio 2015/2017/2019测试运行器没有发现我的xUnit v2测试
- Visual Studio复制项目
- 如何在iis7应用程序池中设置。net Framework 4.5版本
- Visual Studio - Resx文件默认“内部”为“公共”
- 在Visual Studio 2010中有快速查找文件的方法吗?
- Nuget连接尝试失败“无法为源加载服务索引”
- 在Visual Studio中查看多个项目/解决方案
- Visual Studio打开默认浏览器,而不是Internet Explorer
- csproj文件中的“Service Include”是干什么用的?
- 如何在Visual Studio中找到堆栈跟踪?
- 使用不同的Web。在开发和生产环境中进行配置
- 是否有一种方法可以在Visual Studio中删除一行而不剪切它?
- Microsoft Visual Studio的推荐插件
- Visual Studio: ContextSwitchDeadlock