visual-studio 如何在visual studio中调试外部类库项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/654696/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to debug external class library projects in visual studio?
提问by Konstantinos
I have a project(A) that references an assembly from an external project(B) class library that is located in another vs solution.
我有一个项目(A)从位于另一个 vs 解决方案中的外部项目(B)类库中引用一个程序集。
I have yet to understand how i can efficiently debug the class library from B while running the program from project A. Is there something i have to enable on project B such as debug info etc so i can step-into at debug time from A?
我还没有理解如何在从项目 A 运行程序的同时有效地从 B 调试类库。有什么我必须在项目 B 上启用的东西,例如调试信息等,以便我可以在调试时从 A 进入?
Thanks in advance.
提前致谢。
回答by JaredPar
Try disabling Just My Code (JMC).
尝试禁用仅我的代码 (JMC)。
- Tools -> Options -> Debugger
- Uncheck "Enable Just my Code"
- 工具 -> 选项 -> 调试器
- 取消选中“仅启用我的代码”
By default the debugger tries to restrict the view of the world to code that is only contained within your solution. This is really heplful at times but when you want to debug code which is not in your solution (as is your situation) you need to disable JMC in order to see it. Otherwise the code will be treated as external and largely hidden from your view.
默认情况下,调试器会尝试将世界视图限制为仅包含在您的解决方案中的代码。这有时非常有用,但是当您想要调试不在您的解决方案中的代码时(就像您的情况一样),您需要禁用 JMC 才能看到它。否则,代码将被视为外部代码,并且很大程度上隐藏在您的视野之外。
EDIT
编辑
When you're broken in your code try the following.
当您的代码损坏时,请尝试以下操作。
- Debug -> Windows -> Modules
- Find the DLL for the project you are interested in
- Right Click -> Load Symbols -> Select the Path to the .PDB for your other project
- 调试 -> Windows -> 模块
- 找到您感兴趣的项目的 DLL
- 右键单击 -> 加载符号 -> 选择其他项目的 .PDB 路径
回答by TheGateKeeper
This has bugged me for some time. What I usually end up doing is rebuilding my external library using debug mode, then copy both .dll and the .pdb file to the bin of my website. This allows me to step into the libarary code.
这困扰了我一段时间。我通常最终做的是使用调试模式重建我的外部库,然后将 .dll 和 .pdb 文件复制到我网站的 bin 中。这使我可以进入库代码。
回答by Sarath Avanavu
Assume the path of
假设路径为
Project A
项目 A
C:\Projects\ProjectA
Project B
项目 B
C:\Projects\ProjectB
and the dll of ProjectB is in
并且 ProjectB 的 dll 在
C:\Projects\ProjectB\bin\Debug\
To debug into ProjectBfrom ProjectA, do the following
要调试到ProjectBfrom ProjectA,请执行以下操作
- Copy B's dll with dll's.PDBto theProjectA's compiling directory.
- Now debug ProjectA. When code reaches the part where you need to call dll's method or events etc while debugging, pressF11to step into the dll's code.
- 将B的 dll 和 dll 一起复制.PDB到ProjectA的编译目录中。
- 现在调试ProjectA。调试时代码到需要调用dll的方法或事件等部分时,按F11进入dll代码。
NOTE : DO NOT MISS TO COPY THE .PDB FILE
注意:不要错过复制 .PDB 文件
回答by MatrixManAtYrService
I run two instances of visual studio--one for the external dll and one for the main application.
In the project properties of the external dll, set the following:
我运行了两个 Visual Studio 实例——一个用于外部 dll,一个用于主应用程序。
在外部dll的项目属性中,设置如下:
Build Events:
构建事件:
- copy /y "$(TargetDir)$(TargetName).dll" "C:\<path-to-main> \bin\$(ConfigurationName)\$(TargetName).dll"
- copy /y "$(TargetDir)$(TargetName).pdb" "C:\<path-to-main> \bin\$(ConfigurationName)\$(TargetName).pdb"
- copy /y "$(TargetDir)$(TargetName).dll" "C:\<path-to-main> \bin\$(ConfigurationName)\$(TargetName).dll"
- copy /y "$(TargetDir)$(TargetName).pdb" "C:\<path-to-main> \bin\$(ConfigurationName)\$(TargetName).pdb"
Debug:
调试:
- Start external program: - C:\<path-to-main>\bin\debug\<AppName>.exe
- Working Directory - C:\<path-to-main>\bin\debug
- 启动外部程序: - C:\<path-to-main>\bin\debug\<AppName>.exe
- 工作目录 - C:\<path-to-main>\bin\debug
This way, whenever I build the external dll, it gets updated in the main application's directory. If I hit debug from the external dll's project--the main application runs, but the debugger only hits breakpoints in the external dll. If I hit debug from the main project, the main application runs with the most recently built external dll, but now the debugger only hits breakpoints in the main project.
这样,每当我构建外部 dll 时,它都会在主应用程序的目录中更新。如果我从外部 dll 的项目中调试——主应用程序运行,但调试器只在外部 dll 中命中断点。如果我从主项目中调试,主应用程序将使用最近构建的外部 dll 运行,但现在调试器只在主项目中触发断点。
I realize one debugger will do the job for both, but I find it easier to keep the two straight this way.
我意识到一个调试器可以同时完成这两项工作,但我发现以这种方式让两者保持一致更容易。
回答by TripleS
[according to Martin Beckett, the guy who send me this answer ]
[根据 Martin Beckett,给我这个答案的人 ]
You can debug into an external library.
您可以调试到外部库中。
In the project settings tab look for 'visual studio directories' in the 'source code' field include the path to the openCV sources. Then make sure that the .pdb files for each of the debug dll are in the same directory as the dll.
在项目设置选项卡中,在“源代码”字段中查找“视觉工作室目录”,包括指向 openCV 源的路径。然后确保每个调试 dll 的 .pdb 文件与 dll 位于同一目录中。
回答by Stefan Mitic
I was having a similar issue as my breakpoints in project(B) were not being hit. My solution was to rebuild project(B) then debug project(A) as the dlls needed to be updated.
我遇到了类似的问题,因为我在项目(B)中的断点没有被击中。我的解决方案是重建项目(B)然后调试项目(A),因为需要更新 dll。
Visual studio should allow you to debug into an external library.
Visual Studio 应该允许您调试到外部库中。
回答by jasmintmp
NuGet references
NuGet 引用
Assume the -Project_A (produces project_a.dll) -Project_B (produces project_b.dll) and Project_B references to Project_A by NuGet packages then just copy project_a.dll , project_a.pdb to the folder Project_B/Packages. In effect that should be copied to the /bin.
假设 -Project_A(生成 project_a.dll)-Project_B(生成 project_b.dll)和 Project_B 通过 NuGet 包对 Project_A 的引用,然后只需将 project_a.dll、project_a.pdb 复制到文件夹 Project_B/Packages。实际上,应该将其复制到 /bin。
Now debug Project_A. When code reaches the part where you need to call dll's method or events etc while debugging, press F11 to step into the dll's code.
现在调试 Project_A。当代码到了调试时需要调用dll的方法或事件等的部分时,按F11进入dll的代码。

