Visual Studio:如何使用外部可执行文件调试库?
我正在开发一个类库。该库将由另一个程序(一个没有源代码的 .exe)使用。库文件位置作为参数传递给此 exe,例如通过运行: prog.exe lib.dll
我想使用此 .exe 调试库(使用断点等调试工具,等)如何使用 Visual C# 来执行此操作?
我找到了一种可能的方法,即创建一个执行prog.exe lib.dll
的单行程序。当然有更好的方法吗?
I am developing a class library. The library is to be used by another program, an .exe with no source code. The library file location is passed as a parameter to this exe, for example by running: prog.exe lib.dll
I would like to debug the library using this .exe (using debug tools such as breakpoints, etc.) How do I use Visual C# to do this?
I found a possible way, which is creating a one-line program which execute prog.exe lib.dll
. Surely there is a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在项目的调试选项中选择“启动外部程序”并输入exe的路径。开始调试时,VS 将启动 exe,将其作为调试器附加到它。
当您的库加载时,代码上的任何断点都会激活。
需要注意的是:使用外部程序时,请确保它正在加载您正在构建的 dll,如果它正在加载与源代码不匹配的不同版本,事情可能(充其量)会很奇怪。
In the project's debug options select "Start External Program" and enter the path of the exe. On starting debugging VS will start the exe, attach to it as a debugger.
When your library is loaded any breakpoints on your code will activate.
One caveat: with an external program ensure it is loading the dll you are building, things can be (at best) odd if it is loading a different version that doesn't match the source code.
如果您已经有一个使用您的库的外部程序(我假设它也是一个 .net 应用程序),您可以启动该程序并将调试器附加到进程(调试 -> 附加到菜单中的进程)。然后您将能够在类库代码中设置断点并对其进行调试。确保 exe 使用与您的代码(最新版本)同步的 dll 和 pdb 文件。
If you already have an external program that use your library (which then also is a .net application, I will assume), you can start that program and attach the debugger to the process (Debug -> Attach to process in the menu). Then you will be able to set breakpoints in your class library code and debug it. Make sure that the exe uses a dll and pdb file that is in sync with your code (the latest build).