在调试模式下在 Visual Studio 2008 中编辑代码

发布于 2024-08-31 17:07:08 字数 240 浏览 2 评论 0原文

我很想知道是否有一种方法可以在 C# VS 2008 遇到断点并且我正在遍历代码时编辑代码...我可以修改代码吗(例如变量中的值,或者如果我的单步执行行即将遇到 if 语句...我可以修改 if 语句...等)吗? 到目前为止,我必须停止运行VS,修改代码,然后按F5并等待再次命中断点。

当断点命中时,我正在遍历代码,并尝试编辑代码,我收到一条消息“当调试器已附加到正在调试的代码已在运行的进程并在构建时进行了优化时,不允许进行更改”或运行时间。”

I am curious to know if there is a way to edit code in C# VS 2008 right when it has hit a breakpoint and I am walking thru the code... can I modify the code (such as the value in a variable or if my stepthrough line is about to hit an if statement ... can I modify the if statement....etc)?
So far, I have to stop running VS, modify the code, then hit F5 and wait till the breakpoint is hit again.

When the breakpoint hits, and I am walking thru the code, and I attempt to edit the code, I get a message "Changes are not allowed when the debugger has been attached to an already running process of the code being debugged was optimized at build or run time."

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

情未る 2024-09-07 17:07:08

我知道为什么在调试版本中禁用“编辑+继续”的原因只有几个。首先也是最重要的是 64 位操作系统,E+C 仅适用于 32 位代码。使用“项目 + 属性”、“构建”选项卡、“平台目标”= x86 修复该问题。

这也是一个可能已关闭的选项。工具 + 选项、调试、编辑并继续、启用复选框。

如果这没有帮助,请告诉我们更多有关您正在调试的代码类型、启动项目时选择的项目模板、如何让调试器中断以及从“调用堆栈”窗口复制的堆栈跟踪的信息。

There are only a few reasons I know of why Edit+Continue would be disabled in the Debug build. First and foremost is a 64-bit operating system, E+C only works for 32-bit code. Fix that with Project + Properties, Build tab, Platform Target = x86.

It is also an option that might have been turned off. Tools + Options, Debugging, Edit and Continue, Enable checkbox.

If this doesn't help, tell us a bit more about the kind of code you're debugging, the project template you selected when you started the project, how you got the debugger to break and a stack trace copied from the Call Stack window.

小霸王臭丫头 2024-09-07 17:07:08

是的,你可以。
这称为编辑并继续 .
请注意,它有一些限制

编辑:您需要切换到调试版本。

Yes, you can.
This is called Edit and Continue.
Note that it has some limitations.

EDIT: You need to switch to a debug build.

梦里寻她 2024-09-07 17:07:08

要在中断模式下修改变量的值或设置属性,请转到“立即”窗口,设置新值,然后按回车键,例如

strValue = "newValue"
Calendar1.Enabled = true

要检索值,您只需将其打印到窗口 ee

?strValue
?Calendar1.Enabled

To modify the value of a variable or set a property while in break mode go to the Immediate window, set the new value, and hit return e.g.

strValue = "newValue"
Calendar1.Enabled = true

To retrieve a value you can just print it to the window e.e.

?strValue
?Calendar1.Enabled
如梦 2024-09-07 17:07:08
  1. 停止运行您的应用程序。
  2. 转到工具>选项>调试>编辑并继续
  3. 禁用“启用编辑并继续”。
  1. Stop running your app.
  2. Go to Tools > Options > Debugging > Edit and Continue
  3. Disable “Enable Edit and Continue”.
爱殇璃 2024-09-07 17:07:08

针对这个问题的回答:

我可以修改代码吗(比如
变量中的值或者如果我的
逐步执行线即将遇到 if
语句...我可以修改 if
声明......等等)?

您不能直接将新值弹出到变量中,但您可以执行以下操作:

  1. 设置断点
  2. 当遇到该断点时,单击左边距中的箭头并将其向上拖动到上一行
  3. 现在您可以将代码添加到更改环境(例如,您可以将变量设置为新值、从集合中添加/删除项目等)。

请参阅有关启用“编辑和编辑”功能的其他答案。继续 - 特别是确保您处于调试模式。

In response to this question:

can I modify the code (such as the
value in a variable or if my
stepthrough line is about to hit an if
statement ... can I modify the if
statement....etc)?

You cannot pop a new value into a variable directly, but what you can do is this:

  1. Set a breakpoint
  2. When that breakpoint is hit, click on the arrow in the left margin and drag it up to a previous line
  3. Now you can add code to change the circumstances (for example, you can set a variable to a new value, add/remove items from a collection, etc.)

See the other answers about enabling Edit & Continue -- in particular, make sure you're in Debug mode.

陌上芳菲 2024-09-07 17:07:08

为了解决这个问题,我做了以下操作...

BUILD >配置管理器

活动解决方案配置:调试
项目上下文配置:DEBUG

然后 TOOLS >选项>调试>编辑&继续
确保编辑&选择“继续”,

然后“构建”>“清洁解决方案
然后构建>重建解决方案

然后开始调试,然后暂停,然后您的代码应该是可编辑的

To solve this problem I did the following...

BUILD > CONFIGURATION MANAGER

Active solution configuration: DEBUG
project context configuration: DEBUG

then TOOLS > OPTIONS > DEBUGGING > EDIT & CONTINUE
make sure edit & continue is selected

then BUILD > CLEAN SOLUTION
then BUILD > REBUILD SOLUTION

Then start debug, then pause, then your code should be editable

鹿港小镇 2024-09-07 17:07:08

以下答案对我有用:

http://whyiamright.wordpress.com/2007/12/20/aspnet-edit-and-continue-in-visual-studio-2005/

第二点说 - project-properties-web->启用编辑并继续。

就是这样。

Below answer worked for me :

http://whyiamright.wordpress.com/2007/12/20/aspnet-edit-and-continue-in-visual-studio-2005/

The second point says - project-properties-web-> enable edit and continue.

thats it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文