是否有可能找到整个解决方案中的代码行数?我听说过MZ-Tools,但是是否有一个开源的工具?
当前回答
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包括一个很好的行计数器。
不过要记住:
用代码行数来衡量编程进度就像用重量来衡量飞机制造进度。 比尔盖茨
其他回答
显然工具更容易,但我觉得在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}
我发现powershell在这方面很有用。我认为LoC是一个非常虚假的指标,所以我不认为需要任何更正式的东西。
从一个较小的解决方案目录:
PS C:\Path> (gci -include *.cs,*.xaml -recurse | select-string .).Count
8396
PS C:\Path>
这将计算所有解决方案的.cs和.xaml文件中的非空行。对于一个较大的项目,我只是使用了不同的扩展列表:
PS C:\Other> (gci -include *.cs,*.cpp,*.h,*.idl,*.asmx -recurse | select-string .).Count
909402
PS C:\Other>
如果一个命令行就可以做到,为什么要使用整个应用程序呢?:)
Visual Studio有内置的代码度量,包括代码行:
分析→计算代码度量
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/ -不是开源的,但是很容易使用
推荐文章
- 如何在没有任何错误或警告的情况下找到构建失败的原因
- Visual Studio弹出提示:“操作无法完成”
- 为什么我在我的Excel插件中得到“无法在证书存储中找到清单签名证书”?
- Visual Studio拒绝忘记断点?
- Visual Studio展开/折叠键盘快捷键
- Visual Studio:如何在两个单独的选项卡组中看到相同的文件?
- 为什么visual studio 2012找不到我的测试?
- Visual Studio 2010 - c++项目-删除*。自卫队文件
- 如何在Visual Studio中删除未推送的外向提交?
- “无法写入文件…”因为它会覆盖输入文件。”
- 使用Visual Studio调试器在值更改时中断
- Visual Studio 2017:显示方法参考
- 为什么ReSharper想要使用'var'的一切?
- 在Visual Studio中默认从项目中删除安全警告(_CRT_SECURE_NO_WARNINGS)
- 在Visual Studio中设置“首选32位”的目的是什么?它实际上是如何工作的?