<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Janne Mattila's blog : asp.net</title><link>http://blogs.msdn.com/jannemattila/archive/tags/asp.net/default.aspx</link><description>Tags: asp.net</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Attaching debugger to w3wp.exe using nice and easy keyboard shortcut</title><link>http://blogs.msdn.com/jannemattila/archive/2008/10/30/attaching-debugger-to-w3wp-exe-using-nice-and-easy-keyboard-shortcut.aspx</link><pubDate>Thu, 30 Oct 2008 22:56:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9025158</guid><dc:creator>jannemattila</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/jannemattila/comments/9025158.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jannemattila/commentrss.aspx?PostID=9025158</wfw:commentRss><description>&lt;p&gt;How many times have you done some web development and used following method to attach your Visual Studio Debugger to &lt;em&gt;w3wp.exe &lt;/em&gt;(a.k.a. &lt;em&gt;Debug &amp;gt; Attach to Process&lt;/em&gt; –method):    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_7.png"&gt;&lt;img title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_thumb_2.png" width="248" height="164" /&gt;&lt;/a&gt;&amp;#160; &lt;br /&gt;    &lt;br /&gt;And then you scroll the long list and find your &lt;em&gt;w3wp.exe&lt;/em&gt; and press attach:    &lt;br /&gt;&lt;a target="_blank" href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/VSDebugger_2.png"&gt;&lt;img title="VSDebugger" border="0" alt="VSDebugger" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/VSDebugger_thumb.png" width="550" height="381" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I’ll bet that you have done that a lot &lt;strong&gt;:-)&lt;/strong&gt; At least I have.    &lt;br /&gt;    &lt;br /&gt;Let’s create macro that does that very same thing but so that you don’t have to take your fingers of the keyboard.     &lt;br /&gt;First open up &lt;em&gt;Macro Explorer&lt;/em&gt; (using &lt;em&gt;View &amp;gt;&lt;/em&gt; &lt;em&gt;Other windows&lt;/em&gt; &amp;gt; &lt;em&gt;Macro Explorer&lt;/em&gt; or just hit &lt;em&gt;Alt-F8&lt;/em&gt;). Then open up example &lt;em&gt;AttachToCalc &lt;/em&gt;macro under &lt;em&gt;Samples &lt;/em&gt;&amp;gt; &lt;em&gt;VSDebugger&lt;/em&gt;:    &lt;br /&gt;&lt;img title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_3.png" width="198" height="215" /&gt;&amp;#160; &lt;br /&gt;    &lt;br /&gt;Right click and select edit:    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_9.png"&gt;&lt;img title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_thumb_3.png" width="210" height="142" /&gt;&lt;/a&gt;     &lt;br /&gt;    &lt;br /&gt;Copy contents of that and create new macro under &lt;em&gt;My Macros&lt;/em&gt;:    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_11.png"&gt;&lt;img title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_thumb_4.png" width="258" height="108" /&gt;&lt;/a&gt;&amp;#160; &lt;br /&gt;    &lt;br /&gt;And give it a name &lt;em&gt;MyVSDebugger&lt;/em&gt;. Then paste the source code to it. Then modify the process name from &lt;em&gt;calc.exe&lt;/em&gt; to &lt;em&gt;w3wp.exe&lt;/em&gt; and remove the &lt;em&gt;Exit For&lt;/em&gt;. You should have something like this left:&lt;/p&gt;  &lt;p&gt;   &lt;table cellspacing="10"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" align="right"&gt;           &lt;pre&gt;&lt;font color="gray"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27&lt;/font&gt;&lt;/pre&gt;
        &lt;/td&gt;

        &lt;td valign="top"&gt;
          &lt;pre&gt;&lt;font color="#0000ff"&gt;Imports&lt;/font&gt; System
&lt;font color="#0000ff"&gt;Imports&lt;/font&gt; EnvDTE
&lt;font color="#0000ff"&gt;Imports&lt;/font&gt; EnvDTE80
&lt;font color="#0000ff"&gt;Imports&lt;/font&gt; EnvDTE90
&lt;font color="#0000ff"&gt;Imports&lt;/font&gt; System.Diagnostics

&lt;font color="#0000ff"&gt;Public&lt;/font&gt; &lt;font color="#0000ff"&gt;Module&lt;/font&gt; MyVSDebugger

  &lt;font color="#008000"&gt;' This subroutine attaches to w3wp.exe:
&lt;/font&gt;  &lt;font color="#0000ff"&gt;Sub&lt;/font&gt; AttachToW3WP()
    &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; attached &lt;font color="#0000ff"&gt;As&lt;/font&gt; &lt;font color="#0000ff"&gt;Boolean&lt;/font&gt; = &lt;font color="#0000ff"&gt;False
&lt;/font&gt;    &lt;font color="#0000ff"&gt;Dim&lt;/font&gt; proc &lt;font color="#0000ff"&gt;As&lt;/font&gt; EnvDTE.Process

    &lt;font color="#0000ff"&gt;For&lt;/font&gt; &lt;font color="#0000ff"&gt;Each&lt;/font&gt; proc &lt;font color="#0000ff"&gt;In&lt;/font&gt; DTE.Debugger.LocalProcesses
      &lt;font color="#0000ff"&gt;If&lt;/font&gt; (Right(proc.Name, 8) = &lt;font color="#a31515"&gt;&amp;quot;w3wp.exe&amp;quot;&lt;/font&gt;) &lt;font color="#0000ff"&gt;Then
&lt;/font&gt;        proc.Attach()
        attached = &lt;font color="#0000ff"&gt;True
&lt;/font&gt;      &lt;font color="#0000ff"&gt;End&lt;/font&gt; &lt;font color="#0000ff"&gt;If
&lt;/font&gt;    &lt;font color="#0000ff"&gt;Next

&lt;/font&gt;    &lt;font color="#0000ff"&gt;If&lt;/font&gt; attached = &lt;font color="#0000ff"&gt;False&lt;/font&gt; &lt;font color="#0000ff"&gt;Then
&lt;/font&gt;      MsgBox(&lt;font color="#a31515"&gt;&amp;quot;Couldn't find w3wp.exe&amp;quot;&lt;/font&gt;)
    &lt;font color="#0000ff"&gt;End&lt;/font&gt; &lt;font color="#0000ff"&gt;If

&lt;/font&gt;  &lt;font color="#0000ff"&gt;End&lt;/font&gt; &lt;font color="#0000ff"&gt;Sub

End&lt;/font&gt; &lt;/pre&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
Now you should have this kind of view at the &lt;em&gt;Macro Explorer&lt;/em&gt;:

  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_5.png"&gt;&lt;img title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_thumb_1.png" width="176" height="123" /&gt;&lt;/a&gt;

  &lt;br /&gt;

  &lt;br /&gt;Now let’s add keyboard shortcut for our macro from &lt;em&gt;Tools&lt;/em&gt; &amp;gt; &lt;em&gt;Options&lt;/em&gt; and &lt;em&gt;Environment &lt;/em&gt;&amp;gt; &lt;em&gt;Keyboard&lt;/em&gt;:

  &lt;br /&gt;&lt;a target="_blank" href="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_13.png"&gt;&lt;img title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/jannemattila/WindowsLiveWriter/eb0f5b1dcb22_12A25/image_thumb_5.png" width="646" height="377" /&gt;&lt;/a&gt; 

  &lt;br /&gt;Just find your new macro and set focus to &lt;em&gt;Press shortcut keys&lt;/em&gt; field and press your favorite keyboard shortcut and press &lt;em&gt;Assign&lt;/em&gt; and then press &lt;em&gt;OK&lt;/em&gt;. &lt;strong&gt;NOTE:&lt;/strong&gt; You might have another command already using that combination but you can override it if you like.&lt;/p&gt;

&lt;p&gt;Now we’re ready to use that. If you want to build your solution you can Ctrl-Shift-B and if you want to attach to &lt;em&gt;w3wp.exe &lt;/em&gt;you’ll just press &lt;em&gt;Ctrl-Shift-V. &lt;/em&gt;This is extremely handy if you have &lt;em&gt;Post-Build event&lt;/em&gt; nicely set.

  &lt;br /&gt;

  &lt;br /&gt;Anyways... Happy hacking!

  &lt;br /&gt;

  &lt;br /&gt;J&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9025158" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jannemattila/archive/tags/asp.net/default.aspx">asp.net</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/tips+and+tricks/default.aspx">tips and tricks</category><category domain="http://blogs.msdn.com/jannemattila/archive/tags/Visual+Studio/default.aspx">Visual Studio</category></item></channel></rss>