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

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

问题描述

我想使用宏发布web应用我的项目。小问题,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 - Products\04 - 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?

感谢

推荐答案

嘿,伙计们,如果你还在寻找一个答案,这一个尝试。

Hey guys, 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 - Products\04 - Products.WSS").Select(vsUISelectionType.vsUISelectionTypeSelect)
    DTE.ExecuteCommand("ClassViewContextMenus.ClassViewProject.Publish")

    runExternalCommandOnComplete = True

End Sub

然后在EnvironmentEvents补充一点:(注:CustomMacros是你把code以上模块的名称)

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天全站免登陆