Search code examples
c#visual-studio-extensionsvsix

How to get and use Visual Studio command in vsix project


I have a simple Visual Studio extension project which contains a menu item and command.

Here is the command execute function:

private void Execute(object sender, EventArgs e)
{
    ThreadHelper.ThrowIfNotOnUIThread();

    string remoteDebuggerPath = @"C:\Users\mgabbay\Perforce\mgabbay_mgabbay-MOBL_3867\RemoteDebugger\RemoteDebugger.Cli\bin\Debug\netcoreapp3.0\RemoteDebugger.Cli.exe";

    System.Diagnostics.ProcessStartInfo proc = new System.Diagnostics.ProcessStartInfo();
    proc.FileName = @"C:\windows\system32\cmd.exe";
    proc.Arguments = $"/c {remoteDebuggerPath}";
    proc.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;

    var process = System.Diagnostics.Process.Start(proc);

    process.WaitForExit();

    if (process.ExitCode == 0)
    {
        // Run ReAttach to process command here
    }

    process.Dispose(); 
}

I want to do some action on the command and after it's done I want to launch 'ReAttach to process' Visual studio command.

I located the command table on VsDbgCmdUsed.VSCT file.

The command guid is -> "guidVSDebugCommand" and the ID is -> id="cmdidReattach" How can I invoke this command via my extension?

Many thanks.


Solution

  • You can invoke a command with a guid and id with IVsUIShell.PostExecCommand.

    Or just call DTE.ExecuteCommand("Debug.ReattachtoProcess");