如何调试引用的 dll(有 pdb) [英] How to debug a referenced dll (having pdb)

查看:20
本文介绍了如何调试引用的 dll(有 pdb)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作区中有两个解决方案,比如 A 和 B.

I have two solutions in my workspace, say A and B.

解决方案 A 是一个较旧的项目,我前段时间完成了编码.在解决方案 B 中,我需要使用解决方案 A 中的一些类.为此,我添加了对解决方案 A 中某个项目的 dll 的引用.

Solution A is an older project which I finished coding some time ago. In solution B, I need to use some classes from Solution A. To do so, I add a reference to the dll of one of the projects in solution A.

问题是当我尝试调试时.我也希望能够进入 A 的代码.Visual Studio 无法加载这些类的代码(当前位置没有可用的源代码."),我只能查看反汇编,没有用.

The problem is when I try to debug. I want to be able to step into A's code as well. Visual studio is not able to load the code for these classes ("There is no source code available for the current location.") and I can only view the disassembly, which is not useful.

我知道从解决方案 A 调试类的唯一方法是运行解决方案 B,分离所有进程(在调试菜单项中)并从解决方案 A 附加进程.

The only way I know to debug classes from solution A is by running solution B, detach all processes (in the Debug menu item) and attach the process from solution A.

但是这样很不方便,我只能一次性调试A OR B.

However, this is very inconvenient and I can only debug A OR B at once.

有没有办法允许单步执行引用的 dll 的代码(我有源代码)?

Is there a way to allow stepping into the code of referenced dlls (for which I do have the source code)?

解决方案: 我的错误是我认为一个项目只能是单个解决方案的一部分.事实上,一个项目可以是任意数量解决方案的一部分.
当您需要引用旧项目时,您只需将该项目添加到解决方案中即可.这是通过在解决方案资源管理器中右键单击新解决方案 > 添加 > 现有项目来完成的.
然后,您将能够添加项目引用.正如其他人所写,您可能应该完全避免对自己的代码(或您可能需要更改和调试的其他代码)使用 dll 引用.

Solution: My mistake was that I thought that a project can only be part of a single solution. In fact, a project can be part of any number of solutions.
When you need to reference the old project, you should simply add the project to the solution. This is done by right clicking the new solution in the Solution Explorer > Add > Existing Project.
Then, you'll be able to add the project reference. As others wrote, you should probably completely avoid using dll references to your own code (or other code you might need to change and debug).

可以在 MSDN<中找到有关如何设计解决方案的很好参考/a>.

A very good reference to how solutions should be designed can be found in MSDN.

推荐答案

如果您有项目参考,它应该立即生效.

If you have a project reference, it should work immediately.

如果是文件(dll)引用,则需要调试符号(pdb"文件)与dll位于同一文件夹中.检查您的项目是否正在生成调试符号(项目属性 => 构建 => 高级 => 输出/调试信息 = 完整);如果您复制了 dll,请将 pdb 放在一起.

If it is a file (dll) reference, you need the debugging symbols (the "pdb" file) to be in the same folder as the dll. Check that your projects are generating debug symbols (project properties => Build => Advanced => Output / Debug Info = full); and if you have copied the dll, put the pdb with it.

如果您不想复制任何文件,也可以直接在 IDE 中加载符号,但工作量更大.

You can also load symbols directly in the IDE if you don't want to copy any files, but it is more work.

最简单的选择是使用项目引用!

The easiest option is to use project references!

这篇关于如何调试引用的 dll(有 pdb)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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