Programmable reading VS.coveragexml file in C #

So I have code that can read methods from a .coverage file ...

using (CoverageInfo info = CoverageInfo.CreateFromFile(this.myCoverageFile))
{

    CoverageDS ds = info.BuildDataSet();

    foreach (ICoverageModule coverageModule in info.Modules)
    {
        CodeModule currentModule = new CodeModule(coverageModule.Name);
        byte[] coverageBuffer = coverageModule.GetCoverageBuffer(null);

        using (ISymbolReader reader = coverageModule.Symbols.CreateReader())
        {
            Method currentMethod;
            while (reader.GetNextMethod(out currentMethod, coverageBuffer))
            {
                if (currentMethod != null)
                {
                    currentModule.Methods.Add(currentMethod);
                }
            }
        }

        returnModules.Add(currentModule);
    }
}

... but I want to read .coverage files that have been exported to xml too. The reason for this is because .coverage files require the source dll to be where they were when the code coverage was measured, which does not work for me.

When I try to load the coverxml file using CreateFromFile (string), I get the following exception.

Microsoft.VisualStudio.Coverage.Analysis.InvalidCoverageFileException was an unhandled Message = Coverage file "unittestcoverage.coveragexml" - invalid or corrupt.

The coverxml file opens in Visual Studio just fine, so I do not believe that there are any problems in the file format.

, CoverageDS xml , API , , , - ...

using(CoverageInfo info = CoverageInfo.CreateFromFile(fileString))
{
   CoverageDS data = info.BuildDataSet();
   data.ExportXml(xmlFile);
}

..., , .

- , .coveragexml?

+3
2

, , ms_joc.

, "CreateInfoFromFile" .coverage, XML, .

UPDATE: CreateInfoFromFile , coverxml. :

CoverageDS dataSet = new CoverageDS();
dataSet.ImportXml(@"c:\temp\test.coveragexml");

foreach (CoverageDSPriv.ModuleRow module in dataSet.Module)
{
    Console.WriteLine(String.Format("{0} Covered: {1} Not Covered: {2}", module.ModuleName, module.LinesCovered, module.LinesNotCovered));
}
+3

CoverageDS.ReadXml(fileName_string)?

0

Source: https://habr.com/ru/post/1774649/


All Articles