Visual Studio 2008 Macro for Building does not block thread

462 Views Asked by At

I am trying to write a macro for Building my application, kicking off an external tool, and ataching the debugger to that external tool.

Everything is working except for the building. It builds, but it is not blocking the thread so the external tool gets kicked off before it can finish. Is there a way I can run ExecuteCommand and wait for the thread to finish?

Code is below:

    DTE.ExecuteCommand("ClassViewContextMenus.ClassViewProject.Build")
    DTE.ExecuteCommand("Tools.ExternalCommand11")

    Try
        Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
        Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
        Dim dbgeng(1) As EnvDTE80.Engine
        dbgeng(0) = trans.Engines.Item("Managed")
        Dim proc2 As EnvDTE80.Process2 = dbg2.GetProcesses(trans, "MINIPC").Item("_nStep.exe")
        proc2.Attach2(dbgeng)
    Catch ex As System.Exception
        MsgBox(ex.Message)
    End Try
2

There are 2 best solutions below

0
On BEST ANSWER

This was answered on this thread I believe:

Run Visual Studio 2008 Macro on Pre Build Event

0
On

If you attach the debugger to the first process, ClassViewContextMenus.ClassViewProject.Build, as well as the second then presumably the host process would block until the first process is complete. Alternatively get hold of the process handle for the first process in some other way and wait for it to exit. Given the clever debugger stuff you are doing I assume you would know how to do this better than I.