仅在VS Macro IDE中使用旧版本时构建解决方案

时间:2012-10-17 15:11:25

标签: .net visual-studio visual-studio-macros

使用Visual Studio宏IDE,如何判断构建是旧还是过时?

我目前已将我的F5重新映射为运行自定义宏,该宏将进入调试模式并附加到浏览器而不构建解决方案。通常情况下,我总是确保在调试之前按下Control-Shift-B,但我认为我可以更进一步将此过程编程到宏中。这个设置的最好的部分是,如果我自上次构建后没有更改代码,我总是可以跳入和退出调试,而无需像使用普通的Debug(F5)模式那样冗余地重建解决方案。

基本上,我想知道是否有变量或某个进程来判断自上次构建以来代码是否已更改。

这是完整的宏,有???部分显示我正在尝试做什么。如果您愿意,可以自己使用它 - 在调试大型解决方案时节省了大量时间。

Imports System
Imports EnvDTE80
Imports System.Diagnostics

Public Module AttachToWebServer
    Public Sub AttachToWebServer()
        Dim AspNetWp As String = "aspnet_wp.exe"
        Dim W3WP As String = "w3wp.exe"
        Dim buildIsOld As Boolean

        buildIsOld = ???

        If buildIsOld Then
            ' Build the solution and wait for it to finish
            DTE.Solution.SolutionBuild.Build(True)
        End If

        ' Are we at a breakpoint?
        If DTE.Debugger.CurrentMode = EnvDTE.dbgDebugMode.dbgBreakMode Then
            DTE.Debugger.Go() ' Then continue instead of reattaching
        Else ' If not, attach to IIS
            If Not (AttachToProcess(AspNetWp)) Then
                If Not AttachToProcess(W3WP) Then
                    System.Windows.Forms.MessageBox.Show(String.Format("Process {0} or {1} Cannot Be Found", AspNetWp, W3WP), "Attach To Web Server Macro")
                End If
            End If
        End If
    End Sub

    Public Function AttachToProcess(ByVal processName As String) As Boolean
        Dim processFound As Boolean = False
        For Each Process As EnvDTE.Process In DTE.Debugger.LocalProcesses
            If (Process.Name.Substring(Process.Name.LastIndexOf("\") + 1) = processName) Then
                Process.Attach()
                processFound = True
            End If
        Next
        Return processFound
    End Function
End Module

0 个答案:

没有答案