2
votes

I'm trying to export visual studio code coverage files (data.coverage) into xml as described in this blog post from the code analysis team. I've moved the code example in that post into a custom MSBuild task. My custom task references the Microsoft.VisualStudio.Coverage.Analysis.dll located in the PrivateAssemblies folder of Visual Studio.

Right off the bat, trying to load the code coverage file throws an code analysis typed exception ImageNotFoundException, stating that the "Image file fully-qualified-file-path-to-dll could not be found."

 // the following line throws an exception
 CoverageInfo current = 
     CoverageInfo.CreateFromFile( "c:\path\testresults\x\y\z\data.coverage");

The path is fully qualified and the DLL it refers to does exist. My testsettings has this file listed as the assembly to instrument and the "Instrument in place" checkbox is set. I can view code coverage within Visual Studio, so I know coverage is working.

I'm running my MSBuild script from the Visual Studio command line. It looks like this:

<Project ToolsVersion="4.0" DefaultTargets="Default;"
      xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

   <UsingTask TaskName="CustomTasks.MergeCoverageTask" 
      AssemblyFile="CustomTasks.dll" 
      />

   <Target Name="Default">

      <ItemGroup>
         <CoverageFiles Include="**\data.coverage" />
      </ItemGroup>

      <MergeCoverageTask
           CoverageFiles="@(CoverageFiles)"
           OutputFile="output.xml"
           />
   </Target>
 </Project>

Can anyone suggest what I need to do to get this working correctly?

1

1 Answers

7
votes

5 hours later and this is a tumbleweed. I found some additional detail here, which helped get me further down the path.

In order for this to work, you need to include a few additional files alongside the custom task and supply folder locations for the pdb's and instrumented dll's.

Regarding additional files, you need the following:

  1. The custom build task must reference Microsoft.VisualStudio.Coverage.Analysis.dll
  2. Your bin folder must contain the following additional files:

    • Microsoft.VisualStudio.Coverage.Symbols.dll
    • dbghelp.dll
  3. (If you don't have visual studio installed, you must perform regsvr32.exe on msdia100.dll)

Regarding paths to assemblies and symbols, the CreateFromFile method takes a collection of folders to search. What seems really strange is that error complains about not being able to locate missing instrumented assemblies, and it specifies the full path..

Image file c:\project\output\Assembly.dll could not be found.

...but if you specify that path, it doesn't work.

 CoverageInfo current = 
 CoverageInfo.CreateFromFile( "c:\project\testresults\x\In\data.coverage", 
              new string[] { "c:\project\output" },
              new string[] { "c:\project\output" });

However, changing the path to be the folder of the TestResults output works fine:

 CoverageInfo current = 
 CoverageInfo.CreateFromFile( "c:\project\testresults\x\In\data.coverage", 
              new string[] { "c:\project\testresults\x\Out" },
              new string[] { "c:\project\testresults\x\Out" });

I question whether "instrument in place" really means in that folder, or instrument and copy to the MS Test run folder.

Well dear SO folk, if you're reading this, you get a cookie.