【发布时间】: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