DTE.ExecuteCommand 并等待 [英] DTE.ExecuteCommand and wait

查看:18
本文介绍了DTE.ExecuteCommand 并等待的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用宏来发布我的网络应用程序项目.小问题是,DTE.ExecuteCommand 异步运行,我需要等到命令完成.

I would like use macros for publishing my webapplication project. The little problem is, DTE.ExecuteCommand run asynchronously, and I need to wait until the command is done.

示例:

    DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
    DTE.ActiveWindow.Object.GetItem("04 - Products4 - Products.WSS").Select(vsUISelectionType.vsUISelectionTypeSelect)
    DTE.ExecuteCommand("ClassViewContextMenus.ClassViewProject.Publish")
    '// now I want copy (and overwrite) some files, but AFTER the publish

是否有一些同步对象或有关执行命令状态的信息?

Is there some synchronization object or information about state of executed command?

推荐答案

如果您仍在寻找这个问题的答案,试试这个.

If you're still looking for an answer to this one, try this.

绑定到发布事件并在成功推送时调用您的外部命令.我正在做类似的事情来构建解决方案,然后启动 MSpec 测试运行程序 (博文).

Tie into the publish events and on a successful push call your external command. I'm doing a similar thing with building the solution and then firing the MSpec test runner (blog post).

为此,您需要为 PublishEvents_OnPublishDone 添加一个钩子.为此,请转到 EnvironmentEvents 模块并添加以下内容:

To do this you need to add in a hook for PublishEvents_OnPublishDone. Do this by going to the EnvironmentEvents Module and addin the following:

<System.contextStaticAttribute()> Public WithEvents PublishEvents As EnvDTE80.PublishEvents

Private Sub PublishEvents_OnPublishDone(ByVal Success As Boolean) Handles PublishEvents.OnPublishDone
    'call custom module sub here.
End Sub

如果你只想运行外部命令,有时做这样的事情.像这样创建你的宏:

If you only want to run the external command sometimes do something like this. Create your macro like this:

Public runExternalCommandOnComplete As Boolean = False

Sub PublishAndRunExternalCommand()

    DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
    DTE.ActiveWindow.Object.GetItem("04 - Products4 - Products.WSS").Select(vsUISelectionType.vsUISelectionTypeSelect)
    DTE.ExecuteCommand("ClassViewContextMenus.ClassViewProject.Publish")

    runExternalCommandOnComplete = True

End Sub

然后在 EnvironmentEvents 中添加:(注意:CustomMacros 是您放置上面代码的模块的名称)

Then in EnvironmentEvents add this: (Note: CustomMacros is the name of the module where you put the code above)

<System.contextStaticAttribute()> Public WithEvents PublishEvents As EnvDTE80.PublishEvents

Private Sub PublishEvents_OnPublishDone(ByVal Success As Boolean) Handles PublishEvents.OnPublishDone
   CustomMacros.runExternalCommandOnComplete = False
   'Where ExternalCommand1 matches the command you want to run
   DTE.ExecuteCommand("Tools.ExternalCommand1")  
End Sub

应该可以.

这篇关于DTE.ExecuteCommand 并等待的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆