2

有谁知道如何以编程方式(使用 TFS API)确定哪些二进制文件被设置为作为 T​​FS 构建的一部分进行检测?

例如,在具有代码覆盖率的 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);
4

1 回答 1

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);
            }
        }
    }
}
于 2012-05-31T14:00:03.670 回答