C# 在 Visual Studio 解决方案中的某个项目上启用和禁用“步入”调试

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

Enable and disable "Step into" debugging on certain project in a Visual Studio solution

c#visual-studiodebuggingstep-into

提问by SqlRyan

I have a Visual Studio solution with four C# projects in it. I want to step into the code of a supporting project in the solution from my main project, but when I use the "Step into" key, it just skips over the call into that other project. I've set breakpoints in the supporting project, and they're ignored, and I can't for the life of me get it to step into any references to that project.

我有一个包含四个 C# 项目的 Visual Studio 解决方案。我想从我的主项目进入解决方案中支持项目的代码,但是当我使用“进入”键时,它只是跳过对另一个项目的调用。我在支持项目中设置了断点,但它们被忽略了,我一生都无法让它进入对该项目的任何引用。

Everything is set to compile as "Debug", and I've seen Visual Studio warn me that my breakpoints won't be hit before - it doesn't do that in this case. It's as though it looks as though my code will debug, but then at run-time, there's a setting somewhere that tells Visual Studio not to step through the code in that project. All the other projects in my solutions debug without problems.

一切都设置为编译为“调试”,我已经看到 Visual Studio 警告我之前不会命中我的断点 - 在这种情况下它不会这样做。就好像我的代码会调试一样,但是在运行时,某处有一个设置告诉 Visual Studio 不要单步执行该项目中的代码。我的解决方案中的所有其他项目都没有问题地调试。

What box have I checked to cause this behavior?

我检查了哪个框会导致这种行为?

UPDATE FOR CLARITY: The "Just my code" option is currently disabled. Also, since the code belongs to a project in my same solution, I don't think the "Just my code" option applies here. I thought it only applied to pre-compiled code that I didn't have the source for, but since I have the source in my project, I don't think this option has any effect.

清晰度更新:“仅我的代码”选项当前已禁用。此外,由于代码属于我的同一个解决方案中的一个项目,我认为“仅我的代码”选项不适用于此处。我认为它只适用于我没有源代码的预编译代码,但由于我的项目中有源代码,我认为此选项没有任何影响。

采纳答案by SaaS Developer

One thing to check for is that your supporting project assembly has not been installed in the GAC. Open a command prompt and run the following to make sure...

要检查的一件事是您的支持项目程序集尚未安装在 GAC 中。打开命令提示符并运行以下命令以确保...

gacutil /l assemblyName

gacutil /l程序集名称

回答by Brian

Not sure if this is it, but "Tools>Options>Debugging>General:Enable Just My Code" is a possibility. (I prefer to always leave this unchecked.)

不确定是否是这样,但“工具>选项>调试>常规:仅启用我的代码”是可能的。(我更喜欢始终不加检查。)

回答by Jason Down

You need to ensure the supporting projects have pdb files or else Visual Studio will not have the necessary information to step through the code.

您需要确保支持项目具有 pdb 文件,否则 Visual Studio 将没有必要的信息来逐步执行代码。

回答by Neil

A couple of possibilities:

几种可能性:

  • There is a check box to step into "just my code". Its intent is to make it so you can't step into Microsoft's Framework code (unless you choose to by unchecking the box).

  • You might try recompiling the supporting code to make sure the code you're debugging exactly matches the code file you're looking at. VS does care about this and will disable a breakpoint if you put it in the code file whose version doesn't match. Also, make sure the PDB file is in the same directory as the DLL.

  • 有一个复选框可以进入“只是我的代码”。它的目的是使您无法进入 Microsoft 的框架代码(除非您选择取消选中该框)。

  • 您可以尝试重新编译支持代码以确保您正在调试的代码与您正在查看的代码文件完全匹配。VS 确实关心这一点,如果您将断点放在版本不匹配的代码文件中,它将禁用断点。此外,请确保 PDB 文件与 DLL 位于同一目录中。

回答by SqlRyan

It turns out that the assembly needed to be copied into the GAC before it could be debugged. Under the debugging option "Just my code", there's an option to suppress an error if you don't have any user code, and it was suppressing the following error:

事实证明,该程序集需要先复制到 GAC 中才能进行调试。在调试选项“仅我的代码”下,如果您没有任何用户代码,则有一个选项可以抑制错误,并且它正在抑制以下错误:

The Following mobile was built either with optimizations enabled or without debug information. (Module name and path) To debug this module, change its build configuration to Debug mode.

以下手机是在启用优化或没有调试信息的情况下构建的。(模块名称和路径)要调试此模块,请将其构建配置更改为调试模式。

Since I was building it in Debug configuration, I searched on that error message and got this:

由于我在调试配置中构建它,我搜索了该错误消息并得到了这个:

http://claytonj.wordpress.com/2008/01/04/the-following-module-was-built-either-with-optimizations-enabled-or-without-debug-information/

http://claytonj.wordpress.com/2008/01/04/the-following-module-was-built-either-with-optimizations-enabled-or-without-debug-information/

Problem solved. I don't know why it needs to be in the GAC in order for me to step into the project, but it does. I don't ask why, I just ask how, and then I do it...

问题解决了。我不知道为什么它需要在 GAC 中才能让我参与该项目,但确实如此。我不问为什么,我只问怎么做,然后我就去做了……

回答by preethi mali

If you have the source code for the dll's into which you are trying to step into, do the following:

如果您有尝试进入的 dll 的源代码,请执行以下操作:

  1. Click on the project in which these dll's are added as reference and remove them.
  2. Add the Project(s) corresponding to the dll(s) to the solution
  3. Right click on the project -> Add Reference -> Choose the newly added Project(s).
  1. 单击添加这些 dll 作为参考的项目并删除它们。
  2. 将与dll(s)对应的Project(s)添加到解决方案中
  3. 右键单击项目 -> 添加引用 -> 选择新添加的项目。

Now set the break point and debug the code.. You will be able to step into the code.

现在设置断点并调试代码。您将能够进入代码。

The reason for the issue is because you program is still referencing the old dll (without the source code) as it has been added to your project as a reference. Once you remove that dll and add the Project (Source code of the dll) of the dll, Visual studio will be able to step into your code.

问题的原因是因为您的程序仍在引用旧的 dll(没有源代码),因为它已作为参考添加到您的项目中。删除该 dll 并添加该 dll 的项目(dll 的源代码)后,Visual Studio 将能够进入您的代码。

回答by Matas Vaitkevicius

In Visual Studio 2013 one way to cause this behaviour is to set build configuration to Release.
Put it back to Debugand see if that helps.

在 Visual Studio 2013 中,导致此行为的一种方法是将生成配置设置为Release.
把它放回去Debug看看是否有帮助。

enter image description here

在此处输入图片说明