C# 如何在vsix项目中获取和使用Visual Studio命令

C# 如何在vsix项目中获取和使用Visual Studio命令,c#,visual-studio-extensions,vsix,C#,Visual Studio Extensions,Vsix,我有一个简单的VisualStudio扩展项目,其中包含一个菜单项和命令 以下是命令执行功能: private void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); string remoteDebuggerPath = @"C:\Users\mgabbay\Perforce\mgabbay_mgabbay-MOBL_3867\RemoteDebugger\RemoteDe

我有一个简单的VisualStudio扩展项目,其中包含一个菜单项和命令

以下是命令执行功能:

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(); 
}
我想对该命令执行一些操作,完成后我想启动“重新连接到进程”VisualStudio命令

我在VsDbgCmdUsed.VSCT文件中找到了命令表

命令guid为->guidVSDebugCommand,ID为->ID=cmdidReattach 如何通过扩展名调用此命令


非常感谢。

您可以使用guid和id调用命令


或者只需调用DTE.ExecuteCommandDebug.ReattachtoProcess

谢谢你的回复!对于使用DTE.ExecuteCommandDebug.ReattachtoProcess的解决方案;如何获取DTE releavant实例?要获取DTE对象,我在前面添加了此行:EnvDTE.DTE DTE=EnvDTE.DTEMicrosoft.VisualStudio.Shell.ServiceProvider.GlobalProvider.GetServicetypeofEnvDTE.DTE;