visual-studio 在 Visual Studio 中通过不同的解决方案进行调试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2436237/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 11:38:59  来源:igfitidea点击:

Debugging through different solutions in Visual Studio

visual-studiodebugging

提问by Chris Cap

Currently I have solution A that contains a domain layer base and solution B that references the binaries from solution A. Is there a way to debug straight through from one to the other with two instances of Visual Studio open (one for each solution)?

目前我有包含域层基础的解决方案 A 和引用解决方案 A 中的二进制文件的解决方案 B。有没有办法在打开两个 Visual Studio 实例(每个解决方案一个)的情况下从一个直接调试到另一个?

I've read that you can just add the existing projects from solution A to solution B. Is there another solution that works? I've tried directly attaching solution A to what the running executable in solution B, but it won't let me attach multiple debuggers to the same application.

我读过您可以将解决方案 A 中的现有项目添加到解决方案 B 中。还有其他可行的解决方案吗?我已经尝试将解决方案 A 直接附加到解决方案 B 中正在运行的可执行文件,但它不会让我将多个调试器附加到同一个应用程序。

I should note that when I step into a piece of it, it automatically brings up the code from solution A within solution B's instance of Visual Studio to debug in. I suppose this is acceptable, but you can't just set arbitrary breakpoints and wait for the code to hit them this way.

我应该注意到,当我进入它的一部分时,它会自动调出解决方案 B 的 Visual Studio 实例中的解决方案 A 的代码进行调试。我认为这是可以接受的,但您不能只是设置任意断点并等待让代码以这种方式击中它们。

采纳答案by JaredPar

There is no way to have two instances of Visual Studio debugging the same process. This is a limitation of Windows, and most other operating systems in that at most one process can be debugging another.

无法让两个 Visual Studio 实例调试同一进程。这是 Windows 和大多数其他操作系统的限制,因为最多一个进程可以调试另一个进程。

It is a perfectly supported scenario though to debug binaries that are not a part of your solution. As you've noted you can happily step into binaries from Solution B while debugging from a Solution A.

尽管调试不属于您的解决方案的二进制文件,但它是一个完全受支持的场景。正如您所指出的,您可以愉快地从解决方案 B 进入二进制文件,同时从解决方案 A 进行调试。

One item that will get in the way here though is the debugging feature named "Just My Code". This is a feature aimed at minimizing the debugging experience to just the code in your solution. It is great for normal solutions, but bad when you're debugging arbitrary binaries. It's likely causing a lot of the problems around break points you're seeing. You'll want to disable it by doing the following

在这里会遇到的一个问题是名为“Just My Code”的调试功能。这是一项功能,旨在最大限度地减少对解决方案中代码的调试体验。这对于普通解决方案来说很好,但在调试任意二进制文件时就很糟糕。它可能会导致您看到的断点周围出现很多问题。您需要通过执行以下操作来禁用它

  • Menu ToolsOptionsDebugging
  • Unchecked "Enable Just My Code"
  • 菜单工具选项调试
  • 取消选中“仅启用我的代码”

回答by Dean Harding

You can only have one debugger debugging a process at once. So that means you only need one instance of Visual Studio open.

您一次只能让一个调试器调试一个进程。所以这意味着您只需要打开一个 Visual Studio 实例。

However, you can just open the .cpp/.cs/whatever file from Solution B into Solution A's copy of Visual Studio and set breakpoints. It'll still work even though those files aren't actually part of the solution.

但是,您只需将解决方案 B 中的 .cpp/.cs/whatever 文件打开到解决方案 A 的 Visual Studio 副本中并设置断点。即使这些文件实际上不是解决方案的一部分,它仍然可以工作。

回答by Chris

What if you explicitly load the symbols from Solution A?

如果您从解决方案 A 中显式加载符号会怎样?

If you go to menu ToolsOptionsDebuggingSymbols, you can point it at the .pdb file from Solution A.

如果您转到菜单ToolsOptionsDebuggingSymbols,您可以将其指向解决方案 A 中的 .pdb 文件。

Then you can see if the symbols are loaded from your binaries by going to menu DebugWindowsModuleswhile debugging.

然后,您可以通过在调试时转到菜单DebugWindowsModules来查看是否从二进制文件中加载了符号。

回答by CB4

Here is a real and easy solution. Just change your solution properties to use the Multiple Startup Projectssetting and set which project to start simultaneously.

这是一个真实而简单的解决方案。只需更改您的解决方案属性以使用多个启动项目设置并设置要同时启动的项目

Follow this:

按照这个:

Debug Multiple Projects at the Same Time in Visual Studio

在 Visual Studio 中同时调试多个项目

回答by user3048773

There is a simple fix for this.

对此有一个简单的解决方法。

Open both solution files and run them. Stop the second solution instance which you want attach to the process, but make sure that ports are running. Now you can attach the port process to the first solution instance and debug like magic.

打开两个解决方案文件并运行它们。停止要附加到进程的第二个解决方案实例,但确保端口正在运行。现在您可以将端口进程附加到第一个解决方案实例并像魔术一样调试。

回答by Pradeep Reddy

Here is what I did.

这是我所做的。

Say a project from solution A refers to a project from solution B and I want to debug into solution B project from solution A project.

假设解决方案 A 中的一个项目引用了解决方案 B 中的一个项目,我想从解决方案 A 项目中调试到解决方案 B 项目中。

Open solution B in Visual Studio. Set the project properties to "Use Local IIS Wb Server", set the project URL and create a virtual directory.

在 Visual Studio 中打开解决方案 B。将项目属性设置为“使用本地 IIS Wb 服务器”,设置项目 URL 并创建一个虚拟目录。

Open solution A in another Visual Studio instance. Set the project properties to "Use Local IIS Wb Server" and Check "Use IIS Express", set the project URL and create a virtual directory.

在另一个 Visual Studio 实例中打开解决方案 A。将项目属性设置为“使用本地 IIS Wb 服务器”并选中“使用 IIS Express”,设置项目 URL 并创建一个虚拟目录。

Press F5and start debugging the solution B instance of Visual Studio. Then press F5and start debugging the solution A instance of Visual Studio.

F5并开始调试 Visual Studio 的解决方案 B 实例。然后按下F5并开始调试解决方案 A 实例的 Visual Studio。

Now both the instances of Visual Studio will be in debug mode.

现在,两个 Visual Studio 实例都将处于调试模式。

Start from solution A now and you should be able to debug into solution B just like if both projects were in the same solution.

现在从解决方案 A 开始,您应该能够调试到解决方案 B 中,就像两个项目在同一个解决方案中一样。

The key here is to "Use IIS express" for one and "Local IIS Web server" for the other project. This will let you have two debuggers running at once.

这里的关键是对一个项目“使用 IIS express”,对另一个项目“使用本地 IIS Web 服务器”。这将使您同时运行两个调试器。

回答by Anthony Nadar

Ensure the .dll and .pdb files are in the binfolder. You will be able to debug to the other solution opened in the other Visual Studio instance.

确保 .dll 和 .pdb 文件在bin文件夹中。您将能够调试到在其他 Visual Studio 实例中打开的其他解决方案。

We usually have a folder (for example, Dependencies) where the DLL files are referenced from. Place the DLL file in this folder. The DLL files are pushed to this folder when we build the referenced project (using build events. There are other ways too).

我们通常有一个文件夹(例如Dependencies),从中引用 DLL 文件。将 DLL 文件放在此文件夹中。当我们构建引用的项目(使用构建事件。还有其他方法)时,DLL 文件会被推送到此文件夹中。