【问题标题】:Merging Visual Studio Code Coverage fails with ImageNotFoundException合并 Visual Studio 代码覆盖率失败并出现 ImageNotFoundException
【发布时间】:2011-06-30 14:55:29
【问题描述】:

我正在尝试将 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找到了。”

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

路径是完全限定的,并且它引用的 DLL 确实存在。我的 testsettings 将此文件列为要检测的程序集,并设置了“Instrument in place”复选框。我可以在 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>

谁能建议我需要做什么才能使其正常工作?

【问题讨论】:

    标签: visual-studio-2010 code-coverage


    【解决方案1】:

    5 小时后,这是风滚草。我找到了一些additional detail here,这帮助我走得更远。

    为了使其正常工作,您需要在自定义任务旁边包含一些附加文件,并为 pdb 和检测的 dll 提供文件夹位置。

    关于附加文件,您需要以下内容:

    1. 自定义构建任务必须引用 Microsoft.VisualStudio.Coverage.Analysis.dll
    2. 您的 bin 文件夹必须包含以下附加文件:

      • Microsoft.VisualStudio.Coverage.Symbols.dll
      • dbghelp.dll
    3. (如果你没有安装Visual Studio,你必须在msdia100.dll上执行regsvr32.exe)

    关于程序集和符号的路径,CreateFromFile 方法采用一组文件夹进行搜索。看起来很奇怪的是错误抱怨无法找到丢失的检测程序集,它指定了完整路径..

    找不到映像文件 c:\project\output\Assembly.dll。

    ...但是如果你指定了那个路径,它就不起作用了。

     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" });
    

    我质疑“仪器就位”是否真的意味着在那个文件夹中,或者仪器并复制到 MS 测试运行文件夹。

    亲爱的SO伙计们,如果你正在读这篇文章,你会得到一个饼干。

    【讨论】:

    • +1 和谢谢...为我节省了几个小时,即使没有其他人先得到答案!
    • +1 还有一点,就是要添加引用的地方(或者复制Microsoft.VisualStudio.Coverage.Analysis.dll,Microsoft.VisualStudio.Coverage.Symbols.dll等dll, dbghelp.dll )不在您的主项目文件中,而是在使用 CoverageInfo 类的文件中。我花了一些时间来弄清楚在哪里添加引用。此外,Out 文件夹中不应有任何尾随“\”。例如c:\project\testresults\x\Out\ 会报错。
    • 我有 MS2013Pro 版本,但 PrivateAssemblies 文件夹中没有 Symbols.dll 文件。请帮忙!!
    • 我认为 Pro 没有代码覆盖率。这是一项高级功能。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多