gpt4 book ai didi

c# - DTE.ExecuteCommand 并等待

转载 作者:太空狗 更新时间:2023-10-29 19:38:16 26 4
gpt4 key购买 nike

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

例子:

    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

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

最佳答案

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

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

为此,您需要为 PublishEvents_OnPublishDone 添加一个 Hook 。通过转到 EnvironmentEvents 模块并添加以下内容来执行此操作:

<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

如果您只想运行外部命令,有时可以这样做。像这样创建你的宏:

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 是您在上面放置代码的模块的名称)

<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

应该这样做。

关于c# - DTE.ExecuteCommand 并等待,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1000137/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com