ExportDll 通过 ildasm/ilasm 运行后,如何获取程序集的代码覆盖率?

发布于 2024-12-09 10:00:46 字数 800 浏览 1 评论 0原文

我在 C# 程序集上使用构建后步骤来公开 dll 中的函数签名。此步骤使用 http://www.codeproject.com/KB/dotnet/ 中的 ExportDll 工具DllExport.aspx。但是,如果我通过 mstest 运行 dll 并尝试获取代码覆盖率报告,则会收到以下错误:

Instrumentation error while trying to process the file MyAssembly.dll
Error VSP1011 : Unable to obtain debug information. Link with the /Profile linker switch.

考虑到程序集中没有非托管代码(除了一些 P/Invoke 签名之外),这很奇怪。如果我采取构建后步骤,我的代码就会被正确检测,并且我可以获得代码覆盖率报告。因此,我只能得出结论,这一定是构建后步骤,而不是代码本身的某些内容。

我倾向于通过代码的非 ExportDll 版本运行单元测试,同时构建和分发后 ExportDll 版本。由于我主要感兴趣的是代码是否经过测试,而不是其他组件是否可以通过 DLL 导出找到该函数,因此我不认为这是一个糟糕的解决方案。然而,我觉得这可能是构建管理中的一场噩梦,并且必须向团队解释“使用这个程序集,而不是那个程序集”。

有没有人有过对通过此工具运行的 dll 进行单元测试的经验?或者也许有人有使用 ildasm/ilasm 编译、反编译和重新组装的程序集的经验?

I'm using a post-build step on my C# assembly to expose a function signature from my dll. This step uses the ExportDll tool from http://www.codeproject.com/KB/dotnet/DllExport.aspx. However, if I run my dll through mstest and attempt to get a code coverage report, I get the following error:

Instrumentation error while trying to process the file MyAssembly.dll
Error VSP1011 : Unable to obtain debug information. Link with the /Profile linker switch.

This is odd, considering that there is no unmanaged code in the assembly (other than a few P/Invoke signatures). If I take the post-build step out, my code is instrumented properly and I can get a code coverage report. Therefore, I can only conclude that it must be this post-build step and not something in the code itself.

I'm leaning on the idea of running my unit tests through the non-ExportDll version of the code while building and distributing the post-ExportDll version. Since I'm mainly interested in whether or not the code is tested rather than if other components can find the function through the DLL export, I don't see this as a bad solution. However, I feel that it just might be a nightmare in build management and having to explain to the team "use this assembly, not that assembly".

Has anyone had experience unit testing a dll that has been run through this tool? Or perhaps does anyone have experience instrumenting an assembly that has been compiled, decompiled, and reassembled using ildasm/ilasm?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

茶花眉 2024-12-16 10:00:46

ExportDll 实用程序重写原始程序集,但在使用 ilasm。文章似乎没有说这是可能的,但如果您使用 /pdb 开关使用 ilasm,那么这应该会生成一个与新检测的组件兼容的 PDB。

查看源代码,您需要将开关添加到 program.cs 第 348 行,以便指示 ilasm 生成新的 PDB。

The ExportDll utility rewrites the original assembly but it is probably not updating the PDB to take account of the new instrumentation when it recompiles using ilasm.The article doesn't seems to say that this is possible but if you use the /pdb switch with ilasm, then this should produce a PDB that is compatible with your newly instrumented assembly.

Looking at the source code you need to add the switch to program.cs line 348 such that ilasm is then instructed to produce a new PDB.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文