locked
VS2010 Macros do not run RRS feed

  • Question

  • This is my first experience with VS2010 Macros so keep this in mind as you read my description of a problem I am experiencing.  I recorded a macro inside VS2010 but it will not run.  The macro  simply cleans and rebuilds six projects in one solution.  When I runthe macro, it crashes with the following error:

    An exception of type 'System.Runtime.InteropServices.COMException' occurred in VBAssembly but was not handled in user code
    
    Additional information: Error HRESULT E_FAIL has been returned from a call to a COM componen
    

    This error occurs on the second call to DTE.ExecuteCommand.  Here is a portion of the macro:

        DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
    
        DTE.ActiveWindow.Object.GetItem("PDM.MTP\PDM.MTP.DataObjects").Select(vsUISelectionType.vsUISelectionTypeSelect)
        DTE.ExecuteCommand("ClassViewContextMenus.ClassViewProject.Clean")
        DTE.ActiveWindow.Object.GetItem("PDM.MTP\PDM.MTP.DataObjects").Select(vsUISelectionType.vsUISelectionTypeSelect)
        DTE.ExecuteCommand("ClassViewContextMenus.ClassViewProject.Rebuild")
    

    The  actual code is many more lines but I cannot get past these lines since the error occurs on the last line shown above. 

    In reviewing other posts, there seems to be two solutions, either reinstall VS2010 or add missing .dll files.  This error does not seem to be a case of missing .dll files since the ExecuteCommand statement executes at least one time.  But before I reinstall VS2010 - which may or may not be worth the trouble - I thought I'd post this situation to see if anyone else had bumped into this problem.

    To those of you who take the time to review this problem and respon, I Thank you for your effort.

    Tuesday, May 17, 2011 12:09 PM

Answers

  • If all you want to do is rebuild the entire solution (i.e. each project) you could do Build.RebuildSolution, I believe that should do a clean build of the entire solution.

    Ryan

    • Marked as answer by Victor_Chen Wednesday, May 25, 2011 9:16 AM
    Wednesday, May 18, 2011 11:03 PM

All replies

  • 1:  It is unclear why you are using "ClassViewContextMenus.ClassViewProject.Clean/Rebuild" here.  This is the second questionI have seen recently using these specific command placements.  Why are you not using Build.CleanSelection and Build.RebuildSelection?  That would be the more 'normal' approach, though this isn't what your real problem is (see #2).

    2:  The commands you are executing are asynchronous.  So Clean is going to return before it is done, then you try to execute Rebuild but it is still doing the clean so it returns a failure code (E_FAIL).

    I believe Rebuild will do a Clean, so it is unclear why you are calling both commands.  If you need to call both for some reason you will need to wait until the first one finishes before you can execute the second one.

    Ryan

    Tuesday, May 17, 2011 6:56 PM
  • Ryan,

    Thank you for the reponse.  I'm certainly not an expert with VS macros.  But this macro was generated by the software itself, that is, I simply recorded the keystrokes.  I did not realize these command were asynchronous and now the error makes sense.  I will study and implement your tips.  thank you again for your assistance!

    David

    Tuesday, May 17, 2011 7:11 PM
  • Interesting, what keystroke caused that to be recorded I don't see keybindings on any of those commands, or did you execute it via say a context menu during the macro recording?

    Ryan

    Tuesday, May 17, 2011 7:56 PM
  • To record the macro, I used Tools | Macro | Record Temporary Macro.  Yes, I used a context menu to clean and rebuild the project.  All I really wanted was to clean and rebuild each project in the solution.  In exploring your response, I have found that documentation exists but seems to be fairly in depth.  Right now, I do not want to put a large amount of time into learning how macros are written since there are other projects on my desk.  The reason I wanted to create this macro is becuase we are using a code repoisitory and I have found that when I switch to a different file set, it is useful to clean and rebuild each project. 

    I am trying to create a solution to automate testing on our application.  This is easy if Microsoft controls are used but the decision got made to use Q32010 Telerik controls which do not support the UI Framework or MSAA. Thus I have been working with Window API System calls.  I am trying to leverage that approach directly to clean and compile each project.  I might also try using the UI Framework since I would guess that all of the controls used in VS2010 are probably Microsoft controls anyway and therefore support the use of the UIFramework.  But again, this involves yet another "learning curve."

    If you have any thoughts about any of this, please let me know.  I do appreciate your comments and the time you took to think about this problem.

    Wednesday, May 18, 2011 12:04 PM
  • If all you want to do is rebuild the entire solution (i.e. each project) you could do Build.RebuildSolution, I believe that should do a clean build of the entire solution.

    Ryan

    • Marked as answer by Victor_Chen Wednesday, May 25, 2011 9:16 AM
    Wednesday, May 18, 2011 11:03 PM