以编程方式通过数据仓库检索TFS“检测二进制文件”的路径信息

时间:2012-04-20 18:44:40

标签: c# tfs data-warehouse tfs-sdk binaries

有没有人知道如何以编程方式(使用TFS API)确定将哪些二进制文件设置为在TFS上构建的一部分进行检测?

例如,在使用代码覆盖率在TFS上运行构建之后,它会在输出中显示:

...
-> 2 binaries instrumented - 62% of all code blocks covered
        SomeAssembly.dll - 392 blocks covered, 368 blocks not covered
        SomeExe.exe - 584 blocks covered, 241 blocks not covered
...

我想以编程方式确定“SomeAssembly.dll”和“SomeExe.exe”是作为该构建的一部分进行检测的二进制文件。

我已经通过TFS API检索团队项目,但我不确定是否能让我到达我想去的地方:

TfsTeamProjectCollection collection = new TfsTeamProjectCollection(new Uri(versionControlURIRoot + defaultProjectDirectory))
var testManagementService = collection.GetService<ITestManagementService>();
ITestManagementTeamProject teamProject = testManagementService.GetTeamProject(projectName);

1 个答案:

答案 0 :(得分:2)

以下是解决方案:

获取团队项目:

TfsTeamProjectCollection collection = new TfsTeamProjectCollection(new Uri(versionControlURIRoot + defaultProjectDirectory));
    var testManagementService = collection.GetService<ITestManagementService>();
    ITestManagementTeamProject teamProject = testManagementService.GetTeamProject(projectName);

从Build Coverage元数据中提取程序集名称:

List<string> assemblyNames = new List<string>();
if (teamProject != null) {
    ICoverageAnalysisManager coverageAnalysisManager = teamProject.CoverageAnalysisManager;
    if (coverageAnalysisManager != null) {
        IBuildCoverage[] buildCoverage = coverageAnalysisManager.QueryBuildCoverage(buildURI, CoverageQueryFlags.Modules);
        List<string> assemblyNames = new List<string>();
        foreach (IBuildCoverage buildCoverageDetails in buildCoverage) {
            foreach (IModuleCoverage module in buildCoverageDetails.Modules) {
                    assemblyNames.Add(module.Name);
            }
        }
    }
}