9

我想使用宏来发布我的 web 应用程序项目。小问题是,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

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

4

2 回答 2

5

如果你还在寻找这个问题的答案,试试这个。

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

为此,您需要为 PublishEvents_OnPublishDone 添加一个挂钩。通过转到 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

那应该这样做。

于 2009-10-06T02:35:24.710 回答
1

以下是如何编译单个文件,然后链接整个解决方案,例如:

Dim WithEvents t As Timers.Timer

Sub test()
    DTE.ExecuteCommand("Build.Compile")
    t = New Timers.Timer
    t.Interval = 0.05
    t.Start()
End Sub

Sub t_Elapsed(ByVal ee As Object, ByVal dd As Timers.ElapsedEventArgs) Handles t.Elapsed

    If DTE.Solution.SolutionBuild.BuildState <> vsBuildState.vsBuildStateInProgress Then
        t.Stop()
        DTE.ExecuteCommand("Build.Link")
    End If

End Sub
于 2010-02-27T13:57:38.610 回答