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.
Asked
Active
Viewed 544 times
1
-
You can find command guid and ids if you use EnableVSIPLogging https://blogs.msdn.microsoft.com/dr._ex/2007/04/17/using-enablevsiplogging-to-identify-menus-and-commands-with-vs-2005-sp1/ – Simon Mourier Aug 08 '18 at 15:34
2 Answers
0
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

Sergey Vlasov
- 26,641
- 3
- 64
- 66
0
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;

Ionut Enache
- 461
- 8
- 22