The title pretty much says it all. I'm writing a visual studio extension in which i'm creating a custom command. In the callback of this command, i need to invoke the "solution level Build command" at some point in my logic. I found one GlobalInvoke(CommandID commandID) method present in OleMenuCommandService class. The CommandID takes two arguments "CommandID(Guid menuGroup, int commandID)". I could not find the Menu Group Guid for the Build Menu Group. Firstly, am i right in the above approach? If no, please guide me to the right approach. If yes, how can i find the Guids and IDs needed to invoke the Build command? Thanks in Advance.

2

There are 2 best solutions below

1
On BEST ANSWER

You can call DTE.ExecuteCommand("Build.BuildSolution").

If you want to use guid and ID, see the following VB sample:

Sub Run(DTE As DTE2, package As Package)
    Dim cmd As EnvDTE.Command
    Dim shell As Microsoft.VisualStudio.Shell.Interop.IVsUIShell
    Dim arg As Object
    Dim guid As System.Guid
    Dim serviceProvider As System.IServiceProvider
    serviceProvider = New Microsoft.VisualStudio.Shell.ServiceProvider(
               CType(DTE, Microsoft.VisualStudio.OLE.Interop.IServiceProvider))
    shell = serviceProvider.GetService(GetType(Microsoft.VisualStudio.Shell.Interop.SVsUIShell))
    cmd = DTE.Commands.Item("Build.BuildSolution", 0)
    guid = New System.Guid(cmd.Guid)
    shell.PostExecCommand(guid, cmd.ID, 0, arg)
End Sub
0
On

Also if you need to do something at the beginning/end of the build event you can do something like this to catch the event:

mDte.Events.BuildEvents.OnBuildBegin += OnBuildBegin;
mDte.Events.BuildEvents.OnBuildDone += OnBuildDone;

Or you can get the result of your build programmaticaly and check if the build succeed or failed. The exitCode will be 0 if the build succeed and different of 0 otherwise :

int exitCode = DTEObj.Solution.SolutionBuild.LastBuildInfo;