Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何获取TFS集合的总代码行数?_Tfs - Fatal编程技术网

如何获取TFS集合的总代码行数?

如何获取TFS集合的总代码行数?,tfs,Tfs,计算TFS集合中代码行总数的最佳方法是什么?我是否需要以某种方式使用SDK来执行此操作?还是有一个报告工具?< p>我不知道最好的方法,但是你几乎必须把源代码拿到工作区,然后运行你选择的工具来计算“行”(取决于你认为是一行代码)。 源文件中的行数计算工具层出不穷,而且自己编写一个也很简单,所以我不打算详细讨论这部分问题 因此,另一部分是手动将源代码获取到PC,或者使用从批处理文件或类似文件自动获取过程。棘手的一点是找出一个相当不友好的tf命令行,但是如果你仔细阅读文档,这是一个非常容易实现的任务

计算TFS集合中代码行总数的最佳方法是什么?我是否需要以某种方式使用SDK来执行此操作?还是有一个报告工具?

< p>我不知道最好的方法,但是你几乎必须把源代码拿到工作区,然后运行你选择的工具来计算“行”(取决于你认为是一行代码)。 源文件中的行数计算工具层出不穷,而且自己编写一个也很简单,所以我不打算详细讨论这部分问题


因此,另一部分是手动将源代码获取到PC,或者使用从批处理文件或类似文件自动获取过程。棘手的一点是找出一个相当不友好的tf命令行,但是如果你仔细阅读文档,这是一个非常容易实现的任务。

我承认我在试图找到一个很好的理由时不知所措,但是如果你得到了整个集合,然后,您可以计算每个文件中包含代码类型(*.cs、vb、aspx等)的行数


许多工具都可以计算行数,但如果您需要自己的行数,可以尝试计算正则表达式的出现次数,如“+\n”

这是我多年前写的。但它可以在本地文件夹上工作,所以如果您有TFS代码的本地副本,它仍然可以工作。这不是质量最好的代码,但只是一种快速而肮脏的方法,可以在网格中获取报告,并将其复制到Excel(同样,这不是最好的自动化,但可以完成工作)-

[添加表单应用程序中需要的一些控件]

    private static int totalLinesCount = 0;
    private static int totalLinesOfCode = 0;
    private static int totalComments = 0;

    private void btnCount_Click(object sender, EventArgs e)
    {
        try
        {
            totalLinesCount = 0;
            totalLinesOfCode = 0;
            totalComments = 0;
            lblTotalCount.Text = "";
            DirectoryInfo di = new DirectoryInfo(txtFileName.Text);
            if (di.Exists)
            {
                FileInfo[] fis = di.GetFiles(txtSearchPattern.Text, SearchOption.AllDirectories);
                rtbReport.Text = "";
                Dictionary<string, int> dictionary = new Dictionary<string, int>();
                DataSet ds = new DataSet("Report");
                DataTable dt = new DataTable();
                dt.Columns.Add("FileName", typeof(string));
                dt.Columns.Add("TotalCount", typeof(string));
                dt.Columns.Add("Code", typeof(string));
                dt.Columns.Add("Commented", typeof(string));
                dt.Columns.Add("Summary", typeof(string));
                ds.Tables.Add(dt);
                foreach (FileInfo fi in fis)
                {
                    if (fi.Exists)
                    {
                        int fileLinesCount = File.ReadAllLines(fi.FullName).Length;
                        int commentedCode = 0;

                        foreach (string line in File.ReadLines(fi.FullName))
                        {
                            if (line.TrimStart().StartsWith("/") || (line.TrimStart().StartsWith("*")))
                            {
                                commentedCode++;
                            }
                        }

                        rtbReport.Text += string.Format("{0}: {1}; Actual Code: {2}; Commented lines: {3};{4}",
                            fi.Name, fileLinesCount.ToString(), fileLinesCount - commentedCode, commentedCode,"\n");
                        totalLinesCount += fileLinesCount;
                        totalComments += commentedCode;

                        DataRow dr = ds.Tables[0].NewRow();
                        dr["FileName"] = fi.Name;
                        dr["TotalCount"] = fileLinesCount;
                        dr["Code"] = fileLinesCount - commentedCode;
                        dr["Commented"] = commentedCode;
                        dr["Summary"] = string.Format("Code: {0}, Commented: {1}, Total: {2}",
                            fileLinesCount-commentedCode, commentedCode, fileLinesCount);

                        ds.Tables[0].Rows.Add(dr);
                    }
                }
                if (ds.Tables.Count > 0)
                {
                    dataGridView1.DataSource = ds.Tables[0].DefaultView;

                    dataGridView1.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                    dataGridView1.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
                    dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
                }

                totalLinesOfCode = totalLinesCount - totalComments;

                lblTotalCount.Text = string.Format("{0}: {1}; Code: {2}; Comments: {3}",
                    "Total Number of lines in all files", totalLinesCount.ToString(),
                    totalLinesOfCode.ToString(), totalComments.ToString());
                rtbReport.Text += lblTotalCount.Text;
            }
            else
                MessageBox.Show("Folder does not exist. Select a valid folder",
                    "Folder not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
private static int totalinescont=0;
私有静态int totalinesofcode=0;
私有静态int totalComments=0;
私有void btnCount\u单击(对象发送者,事件参数e)
{
尝试
{
TotalinesCount=0;
TotalinesOfcode=0;
totalComments=0;
lblTotalCount.Text=“”;
DirectoryInfo di=新的DirectoryInfo(txtFileName.Text);
如果(di.存在)
{
FileInfo[]fis=di.GetFiles(txtSearchPattern.Text,SearchOption.AllDirectories);
rtbReport.Text=“”;
字典=新字典();
数据集ds=新数据集(“报告”);
DataTable dt=新的DataTable();
添加(“文件名”,类型(字符串));
添加(“TotalCount”,typeof(string));
添加(“代码”,类型(字符串));
添加(“注释”,类型(字符串));
添加(“摘要”,类型(字符串));
ds.Tables.Add(dt);
foreach(fis中的文件信息fi)
{
如果(fi.存在)
{
int filelinescont=File.ReadAllLines(fi.FullName).Length;
int commentedCode=0;
foreach(File.ReadLines(fi.FullName)中的字符串行)
{
if(line.TrimStart().StartsWith(“/”)| |(line.TrimStart().StartsWith(“*”))
{
注释代码++;
}
}
rtbReport.Text+=string.Format(“{0}:{1};实际代码:{2};注释行:{3};{4}”,
fi.Name,filelinescont.ToString(),filelinescont-commentedCode,commentedCode,“\n”);
TotalineScont+=文件行Scont;
totalComments+=commentedCode;
DataRow dr=ds.Tables[0].NewRow();
dr[“FileName”]=fi.Name;
dr[“TotalCount”]=FileLineScont;
dr[“Code”]=filelinescont-commentedCode;
dr[“Commented”]=commentedCode;
dr[“Summary”]=string.Format(“代码:{0},注释:{1},总计:{2}”,
FileLineScont注释代码、注释代码、FileLineScont);
表[0]。行。添加(dr);
}
}
如果(ds.Tables.Count>0)
{
dataGridView1.DataSource=ds.Tables[0].DefaultView;
dataGridView1.Columns[0]。AutoSizeMode=DataGridViewAutoSizeColumnMode.DisplayedCells;
dataGridView1.Columns[0]。DefaultCellStyle.WrapMode=DataGridViewTriState.True;
dataGridView1.AutoSizeRowsMode=DataGridViewAutoSizeRowsMode.AllCells;
}
TotalinesOfcode=TotalinesCount-totalComments;
lblTotalCount.Text=string.Format(“{0}:{1};代码:{2};注释:{3}”,
“所有文件中的总行数”,TotalInesCount.ToString(),
totalinesofcode.ToString(),totalComments.ToString());
rtbReport.Text+=lblTotalCount.Text;
}
其他的
MessageBox.Show(“文件夹不存在,请选择一个有效的文件夹”,
“未找到文件夹”,MessageBoxButtons.OK,MessageBoxIcon.Error);
}
捕获(例外情况除外)
{
MessageBox.Show(例如Message);
}
}

好奇:为什么您关心集合中的代码行?你如何定义“代码”?你是如何定义“行”的?我正试图为一些在TFS中搜索代码的解决方案定价,许多提供解决方案的公司都提供按代码行定价的服务。更奇怪的是:我从来都不需要这样的全局代码搜索功能。你需要它做什么?只查看最新的源代码是否足够智能?它只查看最新的源代码,并在需要时能够搜索历史记录。我们在TFS中也包含数据库对象,因此这将包括所有代码、数据库或C#/VB代码