0

TFS コレクション内のコードの合計行数を把握する最善の方法は何ですか? これを行うには、何らかの方法で SDK を使用する必要がありますか? または、レポートツールはありますか?

4

3 に答える 3

1

最善の方法はわかりませんが、ほぼ確実に、ソース コードをワークスペースに取得し、選択したツールを実行して「行」をカウントする必要があります (「コードの行」と見なすものによって異なります)。 .

ソース ファイルの行数をカウントするツールには終わりがなく、自分で作成するのは簡単なので、問題のその部分については詳しく説明しません。

したがって、他の部分は、手動でソース コードを PC に取得するか、tf.exeを使用してバッチ ファイルなどから取得プロセスを自動化することです。トリッキーなビットは、かなり不親切な tf コマンド ラインを理解することですが、ドキュメントを注意深く読んだだけで、これは非常に簡単に達成できるタスクです。

于 2012-12-14T19:47:57.307 に答える
0

正当な理由を見つけようとして途方に暮れていることは認めますが、コレクション全体を取得すると、コードを含むタイプのすべてのファイルの行数を数えることができます ( *.cs、vb、aspx など)

多くのツールは行を数えることができますが、自分でロールする必要がある場合は、「.+\n」のような正規表現の出現数を数えることができます。

于 2012-12-15T13:29:24.320 に答える
-1

私はこれを何年も前に書いていました。ただし、ローカル フォルダーでは機能するため、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);
        }
    }
于 2014-12-16T03:01:27.710 に答える