Search code examples
visual-studiovspackage

VSpackage how to call operations on the project


Is there a way In a VSpackage to issue a clean on the project from code, to issue a rebuild or a build. So basically is there a way in code to call the commands that appears in the context menu when you left click on a project? (though my current context may not be in solution explorer I may be on the editor window, so calling ExecuteCommand wont work for commands that are only available when I am in the solution explorer)

enter image description here


Solution

  • The SolutionBuild-interface offers various methods that allow performing actions on the solution, e.g. building the solution or a project and cleaning the solution.

    You start at the DTE-object and access the SolutionBuild like this:

    // Builds the solution and waits for the build to finish
    DTE.Solution.SolutionBuild.Build(true); 
    // Show result of build
    MessageBox.Show(string.Format("{0} projects failed to build.", 
                       DTE.Solution.SolutionBuild.LastBuildInfo));