Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I debug faster in Visual Studio?

Every time I have to go to attach to process, then scroll down and find w3wp.exe

Is there a faster way to do this?

like image 863
mrblah Avatar asked Sep 16 '09 22:09

mrblah


2 Answers

I have a macro for this very purpose. In the tools menu, open up Macros -> Macros IDE. In the lefthand pane, double-click MyModule (or create a new module) and paste in this code:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module MyModule
    Sub AttachToIIS()
        Try
            Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
            Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
            Dim dbgeng(2) As EnvDTE80.Engine
            dbgeng(0) = trans.Engines.Item("T-SQL")
            dbgeng(1) = trans.Engines.Item("Managed")
            Dim proc2 As EnvDTE80.Process2 = _
                dbg2.GetProcesses(trans, Environment.MachineName).Item("w3wp.exe")
            proc2.Attach2(dbgeng)
        Catch ex As System.Exception
            MsgBox(ex.Message)
        End Try      
    End Sub
End Module

Then, you can edit your keyboard shortcuts and set this to a new combination; I use Ctrl+Shift+A. The command to invoke will be Macros.MyMacros.MyModule.AttachToIIS.

EDITED: changed "COMPUTERNAME" to Environment.MachineName.

like image 191
Ben M Avatar answered Oct 20 '22 20:10

Ben M


You should be able to debug IIS just as if you are using the Visual Studio web server (Cassini):

  1. Show Properties for you ASP.NET project.
  2. Select the Web tab.
  3. In the Servers section select Use Local IIS Web server. Fill in the Project Url.
  4. Run your project in the debugger by hitting F5 (Debug => Start Debugging).

If you are running on Vista or newer with UAC enabled you will have to run Visual Studio as administrator for this to work. Right click on the Visual Studio shortcut and select Run as Administrator.... Accept the prompt to elevate priviledges.

like image 43
Martin Liversage Avatar answered Oct 20 '22 22:10

Martin Liversage