Force visual studio to always 'rebuild all' when debugging

Cam picture Cam · Mar 4, 2010 · Viewed 14k times · Source

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


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

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 change the 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.

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.

Any ideas?

Answer

Jaguar picture Jaguar · Aug 31, 2010

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

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

UPDATE The 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 will try to build while the debugger is running in some situations. The proper solution is this:

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