views:

839

answers:

4

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?

+1  A: 

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.

Paul Alexander
A: 

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!

filofel
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.
Cam
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...
filofel
Can you expand on that at all?
Cam
Took me some time, but I wanted to check and test before answering:1) Right click on your project properties (left column, solution explorer2) Go to Configuration Properties / Build Events / Pre-build Event3) 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. :)
filofel
+1  A: 

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.

Mark Wilkins
+1  A: 

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
Jaguar
Haha, I can't believe this. I finally have an answer to this after _six months_! Thanks so much :)
Cam
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 everytime
Jaguar