如何调试从外部应用程序调用的类库? [英] How to debug class library that called from external app?

查看:514
本文介绍了如何调试从外部应用程序调用的类库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个外部工作流程执行C#脚本,可以使用DLL文件(我的类库)。



是否可以将调试附加到我的课堂图书馆项目,所以这个WF会调用断点会打中?



谢谢

解决方案>

是的,您可以使用Visual Studio执行此操作。您有两个选择:



配置您的项目以启动外部程序




  1. 打开您的DLL项目。


  2. 在项目的属性上,转到调试选项卡。


  3. 选择启动外部程序,并给出将调用您的DLL的外部程序的路径,以及您可能需要的任何命令行参数供应和工作目录,如果这是相关的。


  4. 保存项目。


  5. 在代码中设置断点,你想要它们。


  6. 按F5开始调试。 (此时,您的断点将表示不会因为符号未加载而受到打击)现在不要担心。)


  7. 做任何事情,使外部应用程序加载您的库并运行代码。






附加到现有流程



如果您无法启动该进程,而是必须附加到已经运行的进程,那么您也可以这样做:



(旁注:如果您使用Visual Studio的Express版本,我不会认为它具有此功能,但我不确定,很容易告诉:您可以在下面的步骤4中提到菜单项。)


  1. 确保进程正在运行。


  2. 打开你的DLL项目。


  3. 设置你的breakpoi nts等。


  4. 调试菜单中,选择附加到... ... p>


  5. 在结果对话框中,找到列表中的过程,将其突出显示,然后点击附加


  6. Visual Studio将进入调试模式。 (此时,您的断点将表示不会因为符号未加载而受到打击)现在不要担心。)


  7. 做任何事情,使外部程序加载并运行代码。


Visual Studio将检测外部进程中的模块加载,加载符号,并停止在断点上。






NB 在这两种情况下,如果外部进程从您项目的 bin / Debug 文件夹之外的其他位置加载DLL,则必须确保复制该DLL到其他位置每次您构建它(您可以设置在项目选项中自动发生)。否则,Visual Studio将无法检测到正在加载的DLL是您要调试的DLL。


There is an external workflow that executes C# scripts and is able to work with DLL files(my class library).

Is it possible to attach debug to my class library project so breakpoint will hit once this WF will call it?

Thanks

解决方案

Yes, you can do this with Visual Studio. You have two options:

Configure your project to start the external program

  1. Open your DLL project.

  2. On the properties for the project, go to the Debug tab.

  3. Choose Start external program and give the path of the external program that will call your DLL, along with any command-line arguments you may need to supply, and the working directory if that's relevant.

  4. Save the project.

  5. Set breakpoints in your code where you want them.

  6. Press F5 to start debugging. (At this point, your breakpoints will say that they won't be hit because the symbols aren't loaded. Don't worry about that for now.)

  7. Do whatever you do to make the external application load your library and run your code.

Visual Studio will detect the module load, load the symbols, and stop on the breakpoint.

Attach to an existing process

If you can't start the process but instead have to attach to a process that's already running, you can do that too:

(Side note: If you're using the "Express" edition of Visual Studio, I don't think it has this feature, but I'm not certain about that. It's easy enough to tell: You'll either have the menu item mentioned on Step 4 below or not.)

  1. Make sure the process is running.

  2. Open your DLL project.

  3. Set your breakpoints, etc.

  4. From the Debug menu, choose Attach to process...

  5. In the resulting dialog box, find the process in the list, highlight it, and click Attach.

  6. Visual Studio will go into debug mode. (At this point, your breakpoints will say that they won't be hit because the symbols aren't loaded. Don't worry about that for now.)

  7. Do whatever you do to make the external process load and run your code.

Visual Studio will detect the module load in the external process, load your symbols, and stop on your breakpoint.


N.B. In both cases, if the external process loads your DLL from somewhere other than the bin/Debug folder of your project, you must make sure you copy the DLL to that other location every time you build it (you can set that up to happen automatically in the project options). Otherwise, Visual Studio won't be able to detect that the DLL being loaded is the one you're trying to debug.

这篇关于如何调试从外部应用程序调用的类库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆