是否可以在 Visual Studio 2010 中编辑并继续而不暂停执行?

发布于 2024-12-22 13:33:20 字数 382 浏览 4 评论 0原文

我最近观看了 Notch 的 Ludum Dare 直播。他在开发游戏时广泛使用 Eclipse 的热插拔功能。 (这是我所指的视频 http://www.twitch.tv/notch/b /302823358?t=86m30s)

我想用 C# 和 XNA 做同样的事情。幸运的是,Visual Studio 具有“编辑并继续”功能。但是,我想在渲染代码运行时编辑它,而不是暂停它。

我可以设置 Visual Studio 来执行相同的操作吗?我注意到有一个复选框用于当一个进程中断时中断所有进程。是否可以在另一个线程中设置渲染循环,以便游戏在我进行更改时保持渲染?

I recently watched a bit of Notch's Ludum Dare live stream. He uses Eclipse's hotswap feature extensively while he works on his game. (here is a video of what I am referring to http://www.twitch.tv/notch/b/302823358?t=86m30s)

I would like to do the same with C# and XNA. Fortunately, Visual Studio has an Edit and Continue feature. However, I would like to edit my rendering code while it is running instead of pausing it.

Is it possible for me to setup Visual Studio to do the same? I noticed that there is a checkbox for Break all processes when one process breaks. Is it maybe possible to set up my rendering loop in another thread so that the game keeps rendering while I make a change?

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

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

发布评论

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

评论(5

零度℉ 2024-12-29 13:33:20

更新:此答案现已作为视频


我一直在努力寻找一种方法来做到这一点。我知道这并不能回答你的确切问题。但实际上您正在寻找的是一个工作流程,您可以在其中以零(或接近零)延迟进行代码更改,并且我想我已经找到了仅使用 Visual Studio 可以获得的最接近结果。 (因此避免了巨大的工程工作和处理“异常”项目)。

实现此工作流程的方法实际上非常简单,一旦您想到它:

使用快捷键!

我想到的第一种方法是仅使用正常的编辑并继续方法来设置断点。只有使用键盘才能更快地完成此操作。这只适用于循环调用的代码(例如:绘制/更新)。单击要修改的代码,添加断点(F9),断点几乎会立即被命中,修改您的代码,删除断点(F9),然后再次运行代码 (F5)。

这很好。您不必使用鼠标点击左侧栏中相对较小的“添加断点”目标。但它确实会将输入焦点移至行首,因此您通常必须再次使用鼠标来修复该问题,然后才能开始编辑。

我想要更快的东西。所以我想出了一个更好的解决方案:

再次使用键盘:按 Ctrl + Alt + Break 来“全部打破” ”。这几乎会立即进入调试器,而不必担心设置断点或要修改的代码是否在循环中运行。这会将编辑器窗口和插入符号焦点更改为执行中断的文档,但您可以通过按“向后导航”的 Ctrl + - 立即修复它。

然后您可以进行编辑,只需按 F5 即可查看它们的实际效果。您只需使用鼠标一次(或根本不用)即可最初选择要开始输入的位置 - 正如您所期望的那样。

诚然,Ctrl + Alt + BreakCtrl + - 是可怕的 您希望能够非常快速地执行某些操作的组合键。如果只按一个键就更好了。

如果您有完整的 Visual Studio,您可能可以将其转换为宏或加载项。 Express 没有这些 - 所以你能做的最好的事情就是修改你的键绑定(工具、自定义、键盘...)并将其绑定到两个相邻的键,你可以快速连续按下这两个键。或者使用外部宏实用程序。

就我个人而言,我已经通过设置为鼠标上备用按钮的宏设置了连续按下的两个组合键(您似乎不需要在两个组合键之间有延迟)。效果相当好 - 因为我通常同时选择文本。我稍后也可能会添加键盘宏。

到目前为止,我已经发现了此方法的两个小缺陷:

  • 当您再次运行该应用程序时,Visual Studio 会为其提供焦点。如果能保持专注就好了。在宏中添加鼠标左键单击是快速重新编辑代码的部分解决方案。
  • “向后导航”不保留文本选择,仅保留插入符号位置。

Update: This answer is now available as a video.


I've been struggling to find a way to do this. I know this doesn't answer your exact question. But really what you are looking for is a workflow where you can make code changes with zero (or near-zero) delay, and I think I've figured out the closest you can get with just Visual Studio. (And therefore avoiding a huge engineering effort and dealing with "abnormal" projects).

The way to achieve this workflow is actually astonishingly simple, once you think of it:

Use shortcut keys!

The first way I came up with is to just use the normal edit-and-continue method of setting a breakpoint. Only by using the keyboard you can do this considerably faster. This only works with code being called in a loop (eg: draw/update). Click the code you want to modify, add a breakpoint (F9), the breakpoint will almost immediately be hit, modify your code, remove the breakoint (F9), and then run the code again (F5).

This is pretty good. You don't have to use the mouse to hit the relatively small "Add breakpoint" target in the left hand column. But it does move the input focus to the beginning of the line, so you generally have to use the mouse again to fix that before you can start editing.

I want something faster. So I came up with a better solution:

Again, using the keyboard: Press Ctrl + Alt + Break to "Break All". This enters the debugger almost instantly, without having to worry about setting a breakpoint or if the code you want to modify is running in a loop. This will change the editor window and caret focus to the document where execution break, but you can then immediately fix it by pressing Ctrl + - for "Navigate Backwards".

Then you can make your edits and simply press F5 to see them in action. You only have to use the mouse once (or not at all) to initially pick where you want to start typing - just as you would expect.

Admittedly Ctrl + Alt + Break and Ctrl + - are horrible key combinations for something you want to be able to do extremely quickly. And it would be better if there was just one key to press.

If you have the full Visual Studio, you could probably turn it into a macro or add-in. Express doesn't have those - so the best you can do is modify your key bindings (Tools, Customise, Keyboard...) and bind it to two keys that are adjacent, that you can press in quick succession. Or use an external macro utility.

Personally I have set up the two key combinations to be pressed in succession (you don't seem to need a delay between the two) by a macro set to a spare button on my mouse. Which works reasonably well - as I'm usually selecting text at the same time. I might add a keyboard macro later too.

So far I've identified two minor pitfalls of this method:

  • When you run the app again, Visual Studio gives it focus. It would be nice if it kept focus. Adding a left mouse click to my macro is a partial solution to quickly re-editing code.
  • "Navigate Backwards" does not retain the text selection, only the caret position.
不如归去 2024-12-29 13:33:20

我可以告诉您如何操作,但您不会喜欢它:

1) 在 Visual Studio 实例中运行游戏可执行文件 (game.exe --> vsInstanceA )

2) 使用单独的 Visual Studio 实例 (modulated.dll --> vsInstanceB) 在单独的 dll 中编写可修改的代码

*注意,这样做可以让您编译你的可修改的.dll,从而进行编译时错误检查等。*

...现在是棘手的地方...

3a) game.exe 需要引用modulated.dll不是 .vcproj,实际的 dll

3b) 当您按下“魔术键”时(让 game.exe 查找按键) ),让 game.exe 卸载 modulated.dll,然后重新加载它。您可以通过 mscorlib 中提供的 Assembly 和 AppDomain 类轻松地完成此操作。当然,这意味着您需要卸载game.exe中的所有依赖系统。

请注意,在这个 3b) 部分中有很多挥手的内容,这是相当多的工作,但非常简单(例如谷歌搜索:https://www.google.com/search?q=dynamic+load+dll+.net)

...之后,您就可以去...

3-alt)如果 3b) 不适合您,还有一些其他选择:

  • 您可以在按下时调用 msbuild.exe 来重建 modulated.dll
    “魔法钥匙”,
  • 您可以使用 CSharp 编译器 dll 来动态地
    重新编译每个类而不是整个可修改的.dll,

但不幸的是,在我 10 多年的 .net 开发中,这是唯一的方法,除非有人创建了第 3 方产品来做到这一点(即:他们为你做了我提到的事情)

i can tell you how, but you arn't going to like it:

1) run your game executable in a visual studio instance (game.exe --> vsInstanceA)

2) code your modifiable code in a seperate dll, using a seperate visual studio instance (modifiable.dll --> vsInstanceB)

*note that doing this lets you compile your modifiable.dll, thus doing compile time error checking, etc.*

... and now is where it get's tricky ...

3a) game.exe needs to reference the modifiable.dll. NOT the .vcproj, the actual dll

3b) when you hit a "magic key" (have game.exe look for a key-press), have game.exe unload the modifiable.dll, and reload it. You can easily do this via the Assembly and AppDomain classes provided in mscorlib. Of course this means you need to unload any dependant systems in game.exe.

note, there's a lot of hand-waving in this 3b) section, it's quite a lot of work but pretty straight forward (example google search: https://www.google.com/search?q=dynamic+load+dll+.net)

... and after that, you are good to go ...

3-alt) some other choices if 3b) doesn't suit you:

  • you can invoke msbuild.exe to rebuild modifiable.dll when you press
    "magic key"
  • you can use the CSharp compiler dll's to dynamically
    recompile each class instead of the entire modifiable.dll

but unfortunatly, in my 10+ years of .net development, this is the only way, unless someone has created a 3rd party product to do it (IE: they do what i mentioned, for you)

明天过后 2024-12-29 13:33:20

这可能不完全是您正在寻找的,但这是我一直在做的。只需在游戏运行时插入一个断点即可。一旦停止,您可以编辑内容,删除断点,然后按 F5 继续。

在大多数情况下,这允许您在游戏运行时编辑内容并在之后继续运行游戏,但它并不适用于所有情况。您无法添加或删除类级别的内容,也无法添加/删除整个函数或参数。大多数情况下,我这样做是为了测试每次更新时遇到的较小事物的不同数字和方程。

This may not be exactly what you're looking for but it's what I've been doing. Just throw in a break point while your game is running. Once it's stopped, you can edit things, remove the break point, and then hit F5 to continue.

For the most part, this allows you to edit things while the game is running and continue running the game afterwards but it doesn't work for everything. You can't add or remove class level things and also can't add/remove entire functions or the parameters. Mostly, I do this to test out different numbers and equations for smaller things that get hit every update.

浮生面具三千个 2024-12-29 13:33:20

回答最初的问题“在 Visual Studio 2010 中不暂停执行?”

不可以。对于 Java,JRebel 允许这样做。

我很快就能想象为什么微软没有这样做——如果你有某种委员会或一群人在设计东西——即使是一个人也很容易提出很好的论据来证明这种“动态软件更新”/热插拔将会被破坏。实在是太容易被击落了。或者,如果他们继续这样做,将通过一些全新的“企业框架”,需要大量的步骤、工作和理解才能实现目标,因为他们想将其用于复杂的在线场景。

我更希望有一些简单的方法来做到这一点 - 我会承担风险,并提出很多免责声明,如果您想要与外部系统通信的热插拔服务,那么您需要使用复杂的框架或其他什么。

可以以低风险安全使用的最典型场景是原型设计和调整某种具有高启动成本或更可能的引擎,以研究引擎中运行的某些内容(如规则)有错误时的行为并展示该错误,很多事情必须发生,并且您可能不会总是遇到该错误。在这种情况下,拥有这个可以节省数周的调试时间,至少在我的情况下是这样。

To answer the original question "in Visual Studio 2010 without pausing execution?"

No. For Java there is JRebel which allows this.

I can quickly imagine why Microsoft haven't done this - if you have some sort of committee or group of people designing things - it's easy for even one person to come up with good arguments where this "dynamic software updating"/hotswap will break. It's just too easy to shoot down. Or if they proceed with it, it will be through some entirely new "enterprise framework" that requires lot of steps, work and understanding to get anywhere, because they want to use it for complicated online scenarios.

I'd prefer there was some simple way to do this - I'll take the risks, and put up a lot of disclaimers that if you want hotswap services that talk to external systems then you need to use that complicated framework or whatever.

The most typical scenario where this could safely be used with low risk is prototyping and tweaking some sort of engine with either high startup cost or more likely, to study behaviour if something running in the engine (like rules) is buggy and to exhibit the bug, a lot of things has to happen and it's possible you don't encounter the bug always. That is the case where having this could save weeks of debugging time, atleast would have in my case.

喜你已久 2024-12-29 13:33:20

我习惯于使用 IntelliJ Idea + DCEVM(动态代码演化 VM)在 Java 中工作。

不幸的是,我在 Microsoft C# 平台上没有找到任何更接近该配置的东西。这真的很糟糕,你对此无能为力。您可以使用一些用户定义的宏,但在编辑并继续模式下,如果不重新启动调试会话,您仍然无法执行太多操作。

但是,如果可以的话,请尝试使用最新的 .NET Core,它可以通过 Dotnet Watch 提供更好的工作效率。仍然不如 DCEVM 快,但比传统的 VS + .NET 热重载体验好得多。 详细信息

I'm used to work in Java using IntelliJ Idea + DCEVM (Dynamic code evolution VM).

Unfortunately i haven't found anything getting closer to that configuration at Microsoft C# platform. It really sucks and you can't do much about it. You can use some user defined macros, but you can't still do much in Edit and Continue mode without restarting Debug session).

However if you can, try to use newest .NET Core which offers much better productivity using Dotnet Watch. Still not so fast as DCEVM but much better than traditional VS + .NET hot reload experience. Details here.

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