Attach to local IIS
While developing an ASP.NET Sitecore application you have several options for how you will step through your code to debug your web app in Visual Studio 2010. You can debug locally using the Visual Studio Development Server, your local IIS server or IIS Express. For this post I will concentrate on attaching to a local IIS server (although the process should be the same for the other servers).
During the course of a normal development day I might attach to the IIS Worker Process 10 or more times. This usually consists of:
- Opening the Attach to Process dialog.
- Selecting the w3wp.exe process.
- Then clicking Attach.
To make my job a little easier (I’m all about 1-click wins), I recorded a Macro to attach to the IIS worker process, added the macro command to my toolbar, then gave it a pretty icon. Here is my Attach to Local IIS button in my Standard toolbar:
Record the Macro
To create the macro you can go to Tools > Macros > Record TemporaryMacro, then follow steps 1-3 from above or just put this code in your macro project (make sure you change the “YOUR-COMPUTER-NAME” variable).
Option Strict Off Option Explicit Off Imports System Imports EnvDTE Imports EnvDTE80 Imports EnvDTE90 Imports EnvDTE90a Imports EnvDTE100 Imports System.Diagnostics Public Module RecordingModule Sub AttachToLocalIIS() 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 (v2.0, v1.1, v1.0)") Dim proc2 As EnvDTE80.Process2 = dbg2.GetProcesses(trans, "YOUR-COMPUTER-NAME").Item("w3wp.exe") proc2.Attach2(dbgeng) Catch ex As System.Exception MsgBox(ex.Message) End Try End Sub End Module
Add the Command to the Standard Toolbar
To add the macro to your toolbar go to Tools > Customize and click the Commands tab, then make sure the Toolbar radio with Standard is selected. Click Add Command.
This will bring up the Add Command dialog. Select Macros from the Categories list, then find/select your macro and click OK.
Click the Move Up/Move Down button to position your command where you like in the toolbar. Now click the Modify Selection button and rename your command, also make sure you have the Default style checked.
You now have a text representation of your Attach to Local IIS Process command in your Standard toolbar. To add a custom icon you have to jump through one more hoop.
Add a Custom Icon to the Command
Visual Studio 2010 does not let you add/change icons to the toolbars, so in order for us to give our new command a pretty icon we need to install Ryan Molden’s VS.NET 2010 CommandingImage extension. Read Ryan’s post on MSDN, Command Image Changing Extension, for installation and usage. For me I did the following:
You should now have a single Icon that will attach to your local IIS with a single click.
Great post! That saves me a lot of time!
Great tip – a time saver no doubt!
This was my favorite time saver on Visual Studio 2010. Unfortunately, Visual Studio 2012 does not support macros anymore 🙁
Help Jose! What should we do??
Response: Installing the “AttachTo” VS Extension solves this problem!
Thanks Boris! Once again you come to the rescue of a damsel in distress.