是否有可能找到整个解决方案中的代码行数?我听说过MZ-Tools,但是是否有一个开源的工具?
当前回答
在Visual Studio Team System 2008中,你可以在Analyze- >菜单中执行“计算解决方案的代码度量”,它将为你提供整个解决方案的行数(其中包括g)。
其他回答
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包括一个很好的行计数器。
不过要记住:
用代码行数来衡量编程进度就像用重量来衡量飞机制造进度。 比尔盖茨
用于VS2008的其他简单工具(开源):http://www.accendo.sk/Download/SourceStat.zip
诀窍在这里。它也会计算Js文件。
http://www.spoiledtechie.com/post/2011/11/22/How-To-Count-Lines-of-Code-in-Visual-Studio.aspx
我想出了一个快速和肮脏的powershell脚本,用于计算文件夹结构中的行数。它不像其他答案中提到的其他工具那样功能齐全,但我认为它足以提供一个项目或解决方案中相对于其他代码文件大小的粗略比较。
脚本可以在这里找到:
https://gist.github.com/1674457
显然工具更容易,但我觉得在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}
推荐文章
- 如何为构造函数定制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