Clean and Rebuild Macro problem

I'm trying to create a macro that will perform a Clean Solution ad then a Rebuild Solution.
When recording a macro doing so it creates:

Public Module RecordingModule

    Sub TemporaryMacro()
        DTE.ExecuteCommand("Build.CleanSolution")
        DTE.ExecuteCommand("Build.RebuildSolution")
    End Sub
End Module

Open in new window


When I run this, I get the following error (after cleaning the solution)

An exception of type 'System.Runtime.InteropServices.COMException' occurred in VBAssembly but was not handled in user code

Additional information: Et kald til en COM-komponent returnerede fejlen HRESULT E_FAIL.

I tried inserting a Threading.Thread.Sleep() but that didn't help.

Any suggestions ?



fc_curlingAsked:
Who is Participating?
 
DanRollinsConnect With a Mentor Commented:
This works...

        DTE.Solution().SolutionBuild().Clean(True)
        DTE.Solution().SolutionBuild().Build(True)

Open in new window


Apparently the Build.CleanSolution command runs asynchronously.  By using the above, you can set the "wait for done" option and that prevents the error.
0
 
fc_curlingAuthor Commented:
How come no one have responded yet ?

0
 
DanRollinsCommented:
Build.RebuildSolution
automatically does a Clean before starting the build.
http://www.codekicks.com/2009/06/difference-between-build-solution-and.html
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
fc_curlingAuthor Commented:
@DanRollins

No it doesn't.
Rebuild forces a rebuild on all projects in the solution, it doesn't make a cleanup of the bin folder first.
0
 
fc_curlingAuthor Commented:
Full points available for a solution-
0
 
DanRollinsCommented:
I don't know why the error occurs, but what I said stands.  
Try it.  Note that the timestamp changes on the DLLs and other files in the BIN folder that are normally deleted by Clean.  They (all of them) are rebuilt during the Rebuild process.
0
 
fc_curlingAuthor Commented:
Perfect Dan, just what I needed.

Do you have any links to any programming references for developing VS Macros and/or AddIns?
0
 
DanRollinsCommented:
No.  I just googled and tested.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.