我正在尝试将 visual studio 代码覆盖率文件 (data.coverage) 导出到 xml,如 this blog post from the code analysis team 中所述.我已将该帖子中的代码示例移至自定义 MSBuild 任务中。我的自定义任务引用了位于 Visual Studio 的 PrivateAssemblies 文件夹中的 Microsoft.VisualStudio.Coverage.Analysis.dll。
马上,尝试加载代码覆盖率文件会抛出代码分析类型的异常 ImageNotFoundException,指出“图像文件 fully-qualified-file-path-to-dll could not be找到了。”
// the following line throws an exception
CoverageInfo current =
CoverageInfo.CreateFromFile( "c:\path\testresults\x\y\z\data.coverage");
路径是完全限定的,它引用的 DLL 确实存在。我的测试设置将此文件列为仪器的程序集,并设置了“就地仪器”复选框。我可以在 Visual Studio 中查看代码覆盖率,因此我知道覆盖率是有效的。
我正在从 Visual Studio 命令行运行我的 MSBuild 脚本。它看起来像这样:
<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>
任何人都可以建议我需要做什么才能使其正常工作吗?
请您参考如下方法:
5 小时后,这是风滚草。我找到了一些 additional detail here ,这帮助我走得更远。
为了使其正常工作,您需要在自定义任务旁边包含一些额外的文件,并为 pdb 和已检测的 dll 提供文件夹位置。
关于附加文件,您需要:
- 自定义构建任务必须引用 Microsoft.VisualStudio.Coverage.Analysis.dll
您的 bin 文件夹必须包含以下附加文件:
- Microsoft.VisualStudio.Coverage.Symbols.dll
- dbghelp.dll
(如果没有安装visual studio,必须对msdia100.dll执行regsvr32.exe)
关于程序集和符号的路径,CreateFromFile 方法采用一组文件夹进行搜索。真正奇怪的是错误提示无法找到丢失的检测程序集,并且它指定了完整路径..
Image file c:\project\output\Assembly.dll could not be found.
...但是如果您指定该路径,它就不起作用。
CoverageInfo current =
CoverageInfo.CreateFromFile( "c:\project\testresults\x\In\data.coverage",
new string[] { "c:\project\output" },
new string[] { "c:\project\output" });
但是,将路径更改为 TestResults 输出的文件夹工作正常:
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" });
我质疑“instrument in place”是否真的意味着在该文件夹中,或者仪器并复制到 MS 测试运行文件夹。
亲爱的 SO 伙计们,如果你正在读这篇文章,你会得到一 block cookies 。