简体   繁体   English

在Visual Studio中使用引用调试项目

[英]debug a project with references in Visual studio

I have two separete c# projects. 我有两个separete c#项目。 One is a helper library that is included as a reference to another main project. 一个是辅助库,作为对另一个主项目的引用。 The main project solution only has a reference to the helper library and not the entire source code there. 主项目解决方案只有对辅助库的引用,而不是那里的整个源代码。 I want to run the main project but also want to be able to debug and step through the code in the helper code. 我想运行主项目,但也希望能够调试并逐步执行帮助程序代码中的代码。 How can I do that? 我怎样才能做到这一点? I have the source code for both projects. 我有两个项目的源代码。

If you compile the library on your machine and include the .PDB files your visual studio should be able to step into the code if you use the Step In command while debugging. 如果您在计算机上编译库并包含.PDB文件,那么如果Step In调试时使用Step In命令,Visual Studio应该能够进入代码。

If you want to breakpoint in that code, file->open then select the .cs file from the other project and set a breakpoint. 如果要在该代码中断点,则file-> open然后从另一个项目中选择.cs文件并设置断点。

Hover your mouse over the breakpoint and it'll say something like: 将鼠标悬停在断点上,它会说:

At Something.cs, line 12 character 34 ('MyOtherLibrary')

This means the debugger is attached to the code in your helper library. 这意味着调试器附加到帮助程序库中的代码。

2 more things: 还有2件事:

  • make sure PDB is loaded for the DLL you are adding. 确保为要添加的DLL加载PDB。 Check if in the "Debug -> Windows -> Modules" window the DLL in question have PDB from the correct path. 检查在“Debug - > Windows - > Modules”窗口中,所讨论的DLL是否具有正确路径的PDB。 If not you can force VS to load PDB by right click -> load symbols on the module in the same window. 如果不是,您可以通过右键单击 - >在同一窗口中的模块上加载符号来强制VS加载PDB。

  • if everything else fails try to turn off "my code only" in Tools -> Options -> Debugging. 如果其他一切都失败,请尝试在工具 - >选项 - >调试中关闭“我的代码”。 This will make VS to try load PDBs for all Dlls and allow breaking on throw for every exception. 这将使VS尝试为所有Dll加载PDB,并允许每次例外中断。

一种方法是将辅助项目添加到主解决方案,而不是使用引用。

如果你有源代码然后添加这个帮助库作为DLL引用,你可以将整个源代码添加到主解决方案(添加 - >现有项目),然后引用辅助项目而不是DLL(在添加之前删除DLL引用项目参考),

You can do either of below: 您可以执行以下任一操作:

  • Create a solution and add helper library to it. 创建一个解决方案并为其添加帮助程序库。 Debugging is easy 调试很简单
  • Build helper project as a debug DLL on your machine and you should be able to step through it. 建立帮助项目作为你的机器上调试DLL,你应该能够逐步完成它。 You can also load files you want to debug by File->Open file 您还可以通过File-> Open file加载要调试的文件

帮助我的是:右键单击项目sln, - >然后选择属性 - >然后转到服务并检查“启用客户端应用程序服务”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM