如何调试 ILMerged 程序集?
摘要
我想更改 2 程序集解决方案的构建过程,以便调用对 ILMerge 的调用,并生成单个程序集的构建结果。此外,我希望能够调试生成的程序集。
准备 - 一个简单的示例
- 新解决方案 - ClassLibrary1
- 在 Class1 中创建静态函数“GetMessage”,返回字符串“Hello world”
- 创建引用 ClassLibrary 的新控制台应用程序。
- 通过控制台从 main() 输出 GetMessage。
您现在有一个 2 程序集应用程序,它将“Hello World”输出到控制台。
那么下一步...?
我想更改控制台应用程序构建过程,包括使用 ILMerge 的构建后步骤,将 ClassLibrary 程序集合并到控制台程序集中
在此步骤之后,我应该能够到:
- 在不存在 ClassLibrary1.dll 的情况下直接运行控制台应用程序
- 通过 VS 中的 F5(或 F11)运行控制台应用程序,并能够调试这 2 个项目中的每一个项目。
成功有限
我读了这篇博文 并设法通过构建后命令...
"$(ProjectDir)ILMerge.bat" "$(TargetDir)" $(ProjectName)
...和一个 ILMerge.bat 文件实现了我想要的合并...
CD %1
Copy %2.exe temp.exe
ILMerge.exe /out:%2.exe temp.exe ClassLibrary1.dll
Del temp.exe
Del ClassLibrary1.*
这工作得相当好,并且实际上生成了一个可以根据需要在 VS 环境之外运行的 exe。然而,它似乎没有生成 VS 能够使用的符号(.pdb 文件)来调试代码。
我认为这是最后一块拼图。
有谁知道我怎样才能做到这一点?
FWIW 我正在 x64 Win7 x64 机器上运行 VS2010。
更新:为什么我要这样做?
有人问:“在调试场景期间我真的需要 ILMerge 吗?”
我的解决方案的程序集需要与其他解决方案(其中一些我可能会开发)的程序集共存于同一文件夹中,
其中一些解决方案将共享对某些程序集的不同版本的依赖项。
因此,Solution1 可能由 Console1 和 ClassLibrary1.dll(v1) 组成,Solution2 可能由 Console2 和 Classlibrary1.dll(v2) 组成。
我认为我可以将依赖项的正确版本合并到解决方案的主程序集中,而不是在 GAC 中注册所有内容,以避免冲突。
然而,目前这使得无法调试该解决方案,我需要与将出现的其他解决方案结合起来进行调试。
这听起来很复杂吗?那是因为它是..:D
Summary
I want to alter the build process of a 2-assembly solution, such that a call to ILMerge is invoked, and the build results in a single assembly. Further I would like to be able to debug into the resultant assembly.
Preparation - A simple example
- New Solution - ClassLibrary1
- Create a static function 'GetMessage' in Class1 which returns the string "Hello world"
- Create new console app which references the ClassLibrary.
- Output GetMessage from main() via the console.
You now have a 2 assembly app which outputs "Hello World" to the console.
So what next..?
I would like to alter the Console app build process, to include a post build step which uses ILMerge, to merge the ClassLibrary assembly into the Console assembly
After this step I should be able to:
- Run the Console app directly with no ClassLibrary1.dll present
- Run the Console app via F5 (or F11) in VS and be able to debug into each of the 2 projects.
Limited Success
I read this blogpost and managed to achieve the merge I was after with a post-build command of...
"$(ProjectDir)ILMerge.bat" "$(TargetDir)" $(ProjectName)
...and an ILMerge.bat file which read...
CD %1
Copy %2.exe temp.exe
ILMerge.exe /out:%2.exe temp.exe ClassLibrary1.dll
Del temp.exe
Del ClassLibrary1.*
This works fairly well, and does in fact produce an exe which runs outside the VS environment as required. However it does not appear to produce symbols (.pdb file) which VS is able to use in order to debug into the code.
I think this is the last piece of the puzzle.
Does anyone know how I can make this work?
FWIW I am running VS2010 on an x64 Win7 x64 machine.
Update: Why do I want to do this?
It's been asked: 'Do I really need to ILMerge during the debug scenario?'
The assemblies of my solution will need to coexist in the same folder as those of other solutions (some of which I will likely develop)
Some of these solutions will share dependencies on different versions of some assemblies.
So Solution1 might be made up of Console1 and ClassLibrary1.dll(v1) and Solution2 might be made up of Console2 and Classlibrary1.dll(v2).
Rather than register everything in the GAC, I thought I could ILMerge the correct version of a dependency into the primary assembly of the solution to avoid a collision.
However this currently renders it impossible to debug the solution, which I need to do in place in conjunction with the other solutions which will be present.
Does this sound complicated? That's because it is.. :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您像我一样仍在使用 ILMerge,那么还有另一种解决方案来调试问题。至少对我来说,调试是在NOT使用可移植 PDB 格式之后开始工作的。我的项目是 .NET Standard 2.0,我在 .NET Framework 下运行它。
If you are still using ILMerge, like I am, there is also an another solution to debugging issues. At least for me the dubugging started working after NOT using the portable PDB format. My project is .NET Standard 2.0 and I was running it under .NET Framework.
我认为 ILMerge 做不到。 red-gate 的 OTOH smartassemble(不是免费的)可以做到这一点,至少它在 功能
是的,我确实同意 Mike 仅将 ILMerge 用于发布版本。
I don't think ILMerge can do it. OTOH smartassembly from red-gate (not free) can do it, at least so it says at features
And yes, I do agree with Mike to only use ILMerge for release versions.
很抱歉您遇到了问题。我没有遵循您的确切步骤,但我创建了一个控制台应用程序 A.exe,它调用 dll B.dll 中的方法。我在调试模式下构建了两个程序集(以便它们具有 PDB 文件)。然后我像这样合并它们:
(实际上A和B在另一个目录中,所以我的命令行有点复杂,但这应该没有什么区别。)ILMerge完成后,有两个文件在当前目录中:foo.exe 和 foo.pdb。然后我输入:
这将打开 Visual Studio,然后我按“F10”启动调试器。我能够单步执行可执行文件中的 Main 方法,然后使用“F11”单步执行原本位于 B.dll 中的方法。调试体验与使用两个程序集的原始 Visual Studio 解决方案中的调试体验完全相同。
如果您仍然遇到问题,请随时将整个解决方案放入 zip 文件中并将其发送给我(mbarnett at microsoft dot com),我可以尝试一下出去。
I'm sorry you're having problems. I didn't follow your exact steps, but I created a console application, A.exe, that called a method in a dll, B.dll. I built both assemblies in Debug mode (so that they had PDB files). I then merged them like this:
(Actually A and B were in another directory so my command line was a little more complicated, but that shouldn't make a difference.) After ILMerge completed, there were two files in the current directory: foo.exe and foo.pdb. I then typed:
This opened up Visual Studio and then I hit "F10" to start the debugger. I was able to step into the Main method in the executable and then used "F11" to step into the method in that had originally been in B.dll. The debugging experience was just the same as it had been in the original Visual Studio solution with the two assemblies.
If you are still having problems, please feel free to put your entire solution into a zip file and send it to me (mbarnett at microsoft dot com) and I can try it out.
我建议您仅 ILMerge 发布程序集的版本。我无法想象合并调试程序集会带来什么好处。
I would suggest that you only ILMerge release builds of your assemblies. I can't imagine any benefit you'd get from merging debug assemblies.
我尝试做这样的事情,发现你不应该重命名任何东西,无论是在合并之前还是之后。将内容移动到单独的目录就可以了。如果您不重命名任何内容,它就会起作用。
I tried to do something like this and found that you should not rename anything, neither before not after the merge. Moving stuff to to separate directory is fine. If you do not rename anything, it works.