Force visual studio to always 'rebuild all' when debugging
Asked Answered
S

5

12

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?

Sextet answered 4/3, 2010 at 4:7 Comment(4)
Try editing the custom build rule and add *.inc to Additional Dependencies. Ultimate fallback is Build + Rebuild.Cacilie
Rebuild is what I'm using right now. Kind of annoying, but I did map ctrl+r to it so it's pretty quick. I'll try the additional dependencies idea and post back on whether or not it worked.Sextet
Also see this answer #1335274Forcefeed
How is this possible with VS2015 ?Wriggler
C
9

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
Companionate answered 31/8, 2010 at 10:2 Comment(3)
Haha, I can't believe this. I finally have an answer to this after six months! Thanks so much :)Sextet
heh i came upon it because i was looking for a solution myself, i had the same problem (on a different scenario though), and was infuriated to see msdn mvp's promoting the idea of rebuilding by hand each and everytimeCompanionate
is it possible for a specific solution only?Liminal
T
6

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.

Thrombosis answered 3/1, 2011 at 19:44 Comment(0)
A
1

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.

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

Animus answered 4/3, 2010 at 4:16 Comment(0)
D
1

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 think the _DTE.ExecuteCommand could be used for this. And if you wanted even more control over the debugger, the Debugger2 interface has quite a bit of functionality exposed.

Demona answered 5/3, 2010 at 13:16 Comment(0)
G
0

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.

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

  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)

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!

Gennagennaro answered 5/3, 2010 at 12:32 Comment(4)
Saving first does not fix the problem - my settings are already that way. Currently I'm using rebuild all before each time i run it, but I'd like to not have to do that.Sextet
And did you consider running a "touch *.asm" in the prebuild step? Not nice, but you at least wouldn't have to think about invoking the unusual rebuild key sequence...Gennagennaro
Can you expand on that at all?Sextet
Took me some time, but I wanted to check and test before answering: 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) 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 said it was a kludge, didn't I? Additionally, the IDE will probably ask you to reload the files. :)Gennagennaro

© 2022 - 2024 — McMap. All rights reserved.