visual-studio 强制 Visual Studio 在调试时始终“全部重建”

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

Force visual studio to always 'rebuild all' when debugging

visual-studiovisual-studio-2010assemblycompilationmasm

提问by Cam

Edit: Basically what I need is for visual studio to always rebuild all when I hit debug.

编辑:基本上我需要的是 Visual Studio 在我点击调试时总是重建所有内容。



I'm currently using visual studio to compile my assembly programs, using MASM and in general it's working fine.

我目前正在使用 Visual Studio 来编译我的汇编程序,使用 MASM 并且总的来说它工作正常。

However I've run into an annoying issue:

但是我遇到了一个烦人的问题:

If I include a file (say, a file with functions) like this

如果我包含这样的文件(例如,具有函数的文件)

Include functions.inc

and compile it, it originally works fine. However if I then changethe contents of functions.inc, this is not recognized and the compilers skips over functions.inc and uses the old version from before I changed it.

并编译它,它最初工作正常。但是,如果我随后更改了functions.inc 的内容,则无法识别,编译器会跳过functions.inc 并使用我更改之前的旧版本。

I cannot find an option anywhere under project properties to fix this. However I'm sure it has something to do with linker options or something - if I make any changes under project properties (even if I change something and change it back, and then press OK), it does compile properly with the new version of functions.inc.

我在项目属性下的任何地方都找不到解决此问题的选项。但是我确定它与链接器选项或其他东西有关 - 如果我在项目属性下进行任何更改(即使我更改某些内容并将其更改回来,然后按 OK),它确实可以使用新版本的功能公司

Any ideas?

有任何想法吗?

采纳答案by Jaguar

You can change the behaviour via the EnvironmentEventsmacro in Visual Studio's Macro Explorer:

您可以通过EnvironmentEventsVisual Studio 的宏资源管理器中的宏更改行为:

Private Enum IDEMode
    Design = 1
    Break = 2
    Run = 3
End Enum

Private _IDEMode As IDEMode = IDEMode.Design

Public Sub DTEDebuggerEvents_OnDebugRun() Handles _
DebuggerEvents.OnEnterRunMode
    If _IDEMode = IDEMode.Design Then
        DTE.ExecuteCommand("Build.RebuildSolution")
    End If
    _IDEMode = IDEMode.Run
End Sub

Public Sub DTEDebuggerEvents_OnDebugDesign() Handles _
    DebuggerEvents.OnEnterDesignMode
    _IDEMode = IDEMode.Design
End Sub

Public Sub DTEDebuggerEvents_OnDebugBreak() Handles _
    DebuggerEvents.OnEnterBreakMode
    _IDEMode = IDEMode.Break
End Sub

This is a VisualStudio change so it will work across all solutions once set

这是 VisualStudio 更改,因此一旦设置,它将适用于所有解决方案

UPDATEThe above solution works, however it has some pitfalls concerning content files where the IDE will change to design mode even if the debugger is running. It willtry to build while the debugger is running in some situations. The proper solution is this:

更新上述解决方案有效,但是它在内容文件方面存在一些缺陷,即使调试器正在运行,IDE 也会更改为设计模式。在某些情况下,它在调试器运行时尝试构建。正确的解决方法是这样的:

Private _curDebugState As EnvDTE80.dbgProcessState

Public Sub debuggerStateChangedHandler
    (ByVal NewProcess As EnvDTE.Process, 
    ByVal processState As EnvDTE80.dbgProcessState) 
    Handles DebuggerProcessEvents.OnProcessStateChanged
    If _curDebugState = dbgProcessState.dbgProcessStateStop And processState = dbgProcessState.dbgProcessStateRun Then
        DTE.ExecuteCommand("Build.RebuildSolution")
    End If
    _curDebugState = processState
End Sub

回答by user492238

Make sure, you have selected the startup project for build in the Configuration Manager:

确保您已在配置管理器中选择了用于构建的启动项目:

Build -> Configuration Manager -> check the 'Build' column for all relevant projects.

构建 -> 配置管理器 -> 检查所有相关项目的“构建”列。

回答by Paul Alexander

Support for ASM code in VS isn't quite as auto-magical as .NET/C++ and you have to help it a bit. We use a MAKE file to compile our ASM code in VS. The MAKE file defines all the dependencies so that changes in the INC files are compiled the next time the ASM file is compiled.

VS 中对 ASM 代码的支持并不像 .NET/C++ 那样具有自动魔力,您必须对其有所帮助。我们使用 MAKE 文件在 VS 中编译我们的 ASM 代码。MAKE 文件定义了所有依赖项,以便在下次编译 ASM 文件时编译 INC 文件中的更改。

A similar build script could be created with MSBuild but we've never taken the time to do that.

可以使用 MSBuild 创建类似的构建脚本,但我们从未花时间这样做。

回答by Mark Wilkins

One possibility might be to create a macro that simply does a rebuild all and then fires off the debugger. Then map the macro to a key. I thinkthe _DTE.ExecuteCommandcould be used for this. And if you wanted even more control over the debugger, the Debugger2interface has quite a bit of functionality exposed.

一种可能性可能是创建一个宏,该宏只进行全部重建,然后启动调试器。然后将宏映射到一个键。我觉得_DTE.ExecuteCommand可以用于此。如果您想对调试器进行更多控制,Debugger2接口公开了相当多的功能。

回答by filofel

If it's a matter of the VS IDE not being able to figure out the dependencies (because it's not able to parse the .asm file and locate the INCLUDE directives there), one brute force solution that works very well with MASM is to rebuild the project or even solution: MASM is very, very fast: I have some very large MASM projects, several tens of .asm modules and even more includes: The largest such project rebuilds in a matter of a (very) few seconds.

如果 VS IDE 无法确定依赖项(因为它无法解析 .asm 文件并在那里找到 INCLUDE 指令),那么与 MASM 配合得很好的一个蛮力解决方案是重建项目甚至解决方案:MASM 非常非常快:我有一些非常大的 MASM 项目,几十个 .asm 模块,甚至更多包括: 最大的此类项目在(非常)几秒钟内重建。

Warning: Kludge squared ahead. Defining a prebuild that does a touch to all you .asm files would automatically force a rebuild...

警告:Kludge 方正前方。定义一个对所有 .asm 文件有影响的预构建将自动强制重建...

  1. Right click on your project properties (left column, solution explorer),
  2. Go to Configuration Properties / Build Events / Pre-build Event
  3. In "command line", type "touch *.asm" (insure you have a touch utility in the path)
  1. 右键单击您的项目属性(左栏,解决方案资源管理器),
  2. 转到配置属性/构建事件/预构建事件
  3. 在“命令行”中,输入“touch *.asm”(确保路径中有触摸实用程序)

Now every time you build, all *.asm files will be touched (ie appear modified) and thus recompiled. And you won't have to remember anymore that you have to rebuild all, as this will happen anyway. I warned it was a kludge, didn't I? Additionally, the IDE will tell you your files were modified outside the editor and do you want to reload them. You can say yes!

现在每次构建时,所有 *.asm 文件都将被触及(即出现修改)并因此重新编译。而且您将不再需要记住您必须重建所有内容,因为无论如何这都会发生。我警告过这是一团糟,不是吗?此外,IDE 会告诉您您的文件已在编辑器外修改,您是否要重新加载它们。你可以说是的!