【问题标题】:How to wait unitl the build command is over in the Visual Studio Add-In?如何在 Visual Studio 加载项中等待构建命令结束?
【发布时间】:2014-05-02 20:41:14
【问题描述】:

我想创建一个 Visual Studio 加载项,该加载项是构建时间的。 到目前为止,这是我的代码:

public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
{
  handled = false;
  if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
  {
    if(commandName == "BuildCurrentSolution.Connect.BuildCurrentSolution")
    {
      var window = _applicationObject.Windows.Item(Constants.vsWindowKindOutput);
      var outputWindow = (OutputWindow)window.Object;
      OutputWindowPane outputWindowPane = null;

      for (var i = 1; i <= outputWindow.OutputWindowPanes.Count; i++)
      {
        if (outputWindow.OutputWindowPanes.Item(i).Name.Equals("BuildCurrentSolution", StringComparison.CurrentCultureIgnoreCase))
        {
          outputWindowPane = outputWindow.OutputWindowPanes.Item(i);
          break;
        }
      }

      if (outputWindowPane == null)
      {
        outputWindowPane = outputWindow.OutputWindowPanes.Add("BuildCurrentSolution");
      }

      outputWindowPane.OutputString("The build has started.\n");
      var sw = new Stopwatch();
      sw.Start();
      _applicationObject.ExecuteCommand("Build.BuildSolution");
      sw.Stop();
      outputWindowPane.OutputString(string.Format("The build has ended. Elapsed time: {0} seconds.\n", sw.Elapsed.TotalSeconds));
      handled = true;
    }
  }
}

不幸的是,它并没有按照我的意愿去做,因为_applicationObject.ExecuteCommand 会立即返回。

是否可以等待命令完成,或者更好的是,是否有一个事件在命令结束时触发?

或者,也许有一种不同的方式来运行构建命令,允许等待或在构建结束时收到通知。

【问题讨论】:

    标签: visual-studio visual-studio-2012 visual-studio-addins


    【解决方案1】:

    我可能太急于提出这个问题。 Automating Visual Studio instance from separate process 包含答案。我应该使用_applicationObject.Solution.SolutionBuild.Build(true); 而不是_applicationObject.ExecuteCommand("Build.BuildSolution");

    就是这样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-13
      • 2017-02-06
      • 2011-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-25
      相关资源
      最近更新 更多