Visual Studio:如何使用外部可执行文件调试库?

发布于 2024-09-25 23:25:42 字数 230 浏览 1 评论 0原文

我正在开发一个类库。该库将由另一个程序(一个没有源代码的 .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 技术交流群。

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

发布评论

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

评论(3

撩起发的微风 2024-10-02 23:25:42

在项目的调试选项中选择“启动外部程序”并输入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.

云之铃。 2024-10-02 23:25:42

如果您已经有一个使用您的库的外部程序(我假设它也是一个 .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).

西瓜 2024-10-02 23:25:42
  1. 你也许可以尝试windbg。有了 sos 扩展,您几乎可以使用 Visual Studio 完成所有操作。
  2. 如果您只想调试该库,那么为什么不能将该库加载到您创建的 exe 中并进入该库,
  1. You can probably try windbg. with the sos extension, it is mearly possible to everything you do with Visual Studio.
  2. If all you want is to debug the library, then why can't you load that library into an exe you created and step inside the library,
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文