Gokul's Blog

Leave a comment

Macro to attach a process to Debug in Visual Studio

When we have to attach a process for debugging in Visual Studio we have to manually do it by navigating to the Debug menu ==> attach to process.

Here is the code which I tweaked a bit to automate this process.
Reference Url: http://consultingblogs.emc.com/howardvanrooijen/archive/2007/06/24/Attach-to-Web-Server-Macro-for-Visual-Studio.aspx

Code (this enhanced code also supports the Visual Studio built in cassini server)

Public Module AttachProcesstoDebug

    Public Sub AttachToWebServer()

        Dim AspNetWp As String = "aspnet_wp.exe"
        Dim W3WP As String = "w3wp.exe"
        Dim Webdev As String = "webdev.webserver.exe"
        If Not (AttachToProcess(Webdev)) Then
            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 Processes As EnvDTE.Processes = DTE.Debugger.LocalProcesses
        Dim Process As EnvDTE.Process
        Dim ProcessFound As Boolean = False

        For Each Process In Processes
            If (Process.Name.Substring(Process.Name.LastIndexOf("\") + 1).ToLower() = ProcessName.ToLower()) Then
                ProcessFound = True
            End If

        AttachToProcess = ProcessFound

    End Function
End Module


Leave a comment

Highlight open file in Solution Explorer, Immediate Window In VS-2008

Taken from: http://stackoverflow.com/questions/1671074/visual-studio-current-file-in-solution-explorer-make-it-darker

Check out Tools > Options > Projects and Solutions, and then check off "Track Active Item in Solution Explorer". This will make whichever file you’re viewing/editing inside of Visual Studio automatically be selected in Solution Explorer and if your Windows color scheme is set up properly, it will in fact be darker.

This option used to be on by default in 2003 and maybe 2005, but 2008 has it disabled by default now… I personally prefer it turned on.


Side Tip:

In Visual Studio 2008 if you want to view Immediate window Press Ctrl+Alt+I