简体   繁体   English

编译时编辑时 Visual Studio 的行为

[英]Behavior of Visual Studio when editing whilst building

In Visual Studio 2017 (15.9.16) I can keep on editing source files after I started a build with the Debug > Start Debugging command (F5).在 Visual Studio 2017 (15.9.16) 中,我可以在使用 Debug > Start Debugging 命令 (F5) 开始构建后继续编辑源文件。 While I am specifically asking this for the C# compiler, it would also be interesting to know if C++ behaves differently.虽然我专门为 C# 编译器询问了这个问题,但知道 C++ 的行为是否不同也会很有趣。

When I edit once the debugger has been attached, and edit-and-continue is enabled, then edits are underlined with squiggly purple and everything is clear.当我在附加调试器后进行编辑并启用编辑并继续时,编辑会用波浪线紫色下划线,一切都清楚了。

When I edit before the debugger has attached, and my edit is saved before the build succeeds, the whole thing appears to be in limbo.当我在调试器附加之前进行编辑,并且在构建成功之前保存我的编辑时,整个事情似乎处于不确定状态。 Either my edit was too late, and the debugger executes the code that has been built (not obvious except for hollow breakpoint bullets, if any).要么我的编辑太晚了,调试器执行已构建的代码(不明显,除了空心断点项目符号,如果有的话)。 Or it was timely, and is included.或者它是及时的,并且被包括在内。

Where is the point in a build's timeline when it is decided if a recent edit will still be included?在决定是否仍包含最近的编辑时,构建时间表的重点在哪里? By the timestamp the build started?通过构建开始的时间戳? Indeterminate?不定? Immediately before the source file is processed by the compiler?紧接在源文件被编译器处理之前? Does the linker check if the obj was generated from a source that changed after it started?链接器是否检查 obj 是否是从启动后更改的源生成的?

Behavior of Visual Studio when editing whilst building编译时编辑时 Visual Studio 的行为

Faced with this behavior, C# and C++ projects show two different manifestations:面对这种行为, C#C++项目表现出两种不同的表现:

For c# project,actually, when you check the option Enable Edit and Contniue , the code changes will be applied into the debugger only when you return the breakpoint execution arrow to the change part.对于c#项目,实际上,当你勾选Enable Edit and Contniue选项时,只有当你将断点执行箭头返回到更改部分时,代码更改才会应用到调试器中。 But the changes are being put into a temporary library, only for debugging purposes, and are not being built into the output path( obj and bin ).但是这些更改被放入一个临时库中,仅用于调试目的,并没有被构建到输出路径( objbin )中。 Include this only if you start the build when you interrupt and debug again.仅当您在中断和再次调试时开始构建时才包含此项。 That's the C# mechanism.这就是 C# 机制。

And this is the opposite of a C++ project.这与 C++ 项目相反。

For C++ projects, when you move the cursor to the modified part of a c++ project, it triggers build task to recompile the project, which will include these changes directly.对于C++项目,当您将光标移动到C++项目的修改部分时,它会触发构建任务重新编译该项目,该任务将直接包含这些更改。 It is the time which includes the modified part in the build process.这是在构建过程中包含修改部分的时间。

how long into the build process can you save changes to source files so their latest version will still be included in the ongoing build's output?在构建过程中多久可以保存对源文件的更改,以便它们的最新版本仍将包含在正在进行的构建输出中?

For C++ projects, Once you move the cursor to the modified part to trigger the rebuild task, the modified part is permanently included in the build file.对于C++项目,一旦将光标移动到修改部分触发重建任务,修改部分将永久包含在构建文件中。 During this process, you do not need to build your project again.在此过程中,您无需再次构建项目。

If you debug a C# project, when you move the cursor to the modified part, this does not trigger the automatic build task, so this part is not automatically included in the output file, but only in the current debugging phase.如果你调试一个C#项目,当你将光标移动到修改的部分时,这不会触发自动构建任务,所以这部分不会自动包含在输出文件中,而只是在当前调试阶段。

So when you finish the crrent debugging proecess and then start debug again which will trigger the build process or click build button directly so that these edits can be permanently included in the build file.因此,当您完成 crrent 调试过程然后再次开始调试时,这将触发构建过程或直接单击构建按钮,以便这些编辑可以永久包含在构建文件中。

Overall , when you click the debug button, the build process will be triggered automatically, so you can debug later.总的来说,当您点击调试按钮时,构建过程会自动触发,因此您可以稍后进行调试。 Once the build is triggered, these parts are permanently included in the build file.一旦触发构建,这些部分将永久包含在构建文件中。

And you can see all of these on the Output window.您可以在“输出”窗口中看到所有这些。

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

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