40

Since VS11 removed macros, I can no longer fire this macro to attach to the webserver using a keyboard shortcut.

Is there another way to start the debugger and attach to a specific process with a keyboard shortcut in VisualStudio 2012?

JeremyWeir
  • 24,118
  • 10
  • 92
  • 107

6 Answers6

43

Install AttachTo extension, and bind the shortcut key to Tools.AttachToIIS.

mika
  • 6,812
  • 4
  • 35
  • 38
  • 2
    It would take almost 2 min to build and load symbols. Now with this attach to process extension it goes into debugging mode almost in 5 sec – Krishh Apr 05 '13 at 18:41
  • for 2013: http://moderngeekdad.com/visual-studio-2012-shortcut-to-attach-to-iisexpress/ – parliament Dec 03 '14 at 01:02
  • This is a really quick and easy way to attach to process. Great Solution. – KyleK Jun 24 '15 at 12:28
  • 1
    Since the `AttachTo` extension is not supported by vs 2015, I suggest another one: [ReAttach](https://visualstudiogallery.msdn.microsoft.com/8cccc206-b9de-42ef-8f5a-160ad0f017ae) – Mahmood Dehghan Dec 20 '15 at 10:44
40

The debugger in visual studio automatically attaches to the web server if you check that box in the project properties. A macro has never been necessary for that.

Check the "Use Local IIS Web server" box in Visual Studio, on the "Web" tab of your project properties. Then check the "ASP.NET" box at the bottom, under "Debuggers"

To debug, just hit F5.

EDIT

To get F5 to simply attach to w3wp.exe...

Make sure you have a web project set as the StartUp project enter image description here

On that web project's settings Web tab, just select "Use Local IIS Web server" and put in the url you use to go to your site (the url really only matters if you keep the Start Action on "Current Page"). I don't like having a browser get launched, because there's a good chance I'm actually on another site in the project. But what's great is once it attaches to w3wp.exe, it'll be debugging any site. enter image description here

JeremyWeir
  • 24,118
  • 10
  • 92
  • 107
dodexahedron
  • 4,584
  • 1
  • 25
  • 37
  • I don't use the local IIS web server, I use w3wp.exe proper – JeremyWeir Jun 22 '12 at 23:14
  • 3
    The difference being? w3wp.exe IS IIS. I'm not talking about IIS Express or the VS Dev Server. That comment makes no sense. – dodexahedron Jun 22 '12 at 23:15
  • 1
    In a solution with non web projects this might not be available for the project that's currently being edited. This might be a good method if all of the projects were web. So not a perfect solution. – iamwill Jun 22 '12 at 23:20
  • I'm not sure what you mean, there. I have a project open right now with three class libraries and an ASP.NET MVC project. If I debug the MVC project, which is attached to IIS, and an exception is thrown in ANY of the projects, visual studio drops into the debugger and jumps to the offending line. Other projects have nothing to do with this. If you have a project that consumes the web project in the same solution, just start the debugger once for the ASP project and then right-click on the other project to start a second debugger for it. – dodexahedron Jun 22 '12 at 23:23
  • You're right, I thought you were talking about the dev server. I'll see if I can get that to work with my exising sites since they require specific hostnames and ssl certs – JeremyWeir Jun 22 '12 at 23:29
  • Hmm. That's interesting. What do certs and hostnames have to do with debugging the application? I'm just curious. – dodexahedron Jun 22 '12 at 23:32
  • We have a number of sites that communicate with each other, share cookies and are all under https always. Having dev hosting environments set almost identically to production simplifies things a lot. – JeremyWeir Jun 22 '12 at 23:39
  • Gotcha. If it helps you at all, it is possible to override .NET's handling of certificates and blindly accept any certificate. I do that in a few projects that utilize HTTPS to simplify debugging. Just remember to make that code conditional so you don't end up opening a hole in your production application. – dodexahedron Jun 22 '12 at 23:42
  • I'm trying to wrap my head around how this Use Local IIS works. What is it doing when I press F5? I would think it would just open a browser to the project url I have specified and attach the debugger to w3wp.exe. But something else must be going on because I'm getting a weird wcfsvchost.exe config error. And it is an mvc web app. – JeremyWeir Jun 22 '12 at 23:56
  • Do you have a WCF project in the same solution? If so, then be sure that your web project is set as the startup project, and then also see this post, to ensure that the WCF debugger is not launched when you're not debugging that project: http://stackoverflow.com/q/283145/1071834 – dodexahedron Jun 23 '12 at 00:26
  • Oh duh, its been so long since I've used VS in that way, I had a class library set as the default startup project. – JeremyWeir Jun 23 '12 at 00:27
  • 1
    Awesome, pair that with "Don't open a page. Wait for a request from an external application" and it works great. I'll update your answer with some screenshots and accept. – JeremyWeir Jun 23 '12 at 00:32
  • Great to hear it. Happy coding. – dodexahedron Jun 23 '12 at 00:37
  • Thanks for the screenshots. I didn't have my VS11 install in front of me (VS 2010 on this particular machine) so my screenshots would have been slightly less perfect (though still almost identical). – dodexahedron Jun 23 '12 at 00:45
  • The only problem I have with using local IIS is that it requires me to run Visual Studio as administrator. – Peter Hedberg Aug 16 '12 at 00:24
  • But it causes to build the project which is not usefull in most cases. I prefer AttachTo extention to this approach. – Mahmoud Moravej Oct 01 '12 at 13:11
  • maybe not appropriate solution for multi tenant web apps with multiple host headers – Daniel Kereama Jun 01 '16 at 00:55
10

In response to Cory's answer, you don't need to create your own shortcut. CTRL+ALT+P opens the attach to process dialog, then you can use his suggestion and type "w" to find the IIS process in the list.

This is also useful if you are remote debugging and therefore don't have a local process to attach to automatically.

If you are working with IIS on your local machine, then you can set it up as a local IIS web server or Custom Web Server in the "Web" tab of your project's properties.

Jeremy
  • 502
  • 2
  • 9
7

Sad that macros were removed in VS 2012, but you can use hotkeys :)

Ctrl+Alt+P Press w (should find first one which in 99% is w3wp) Press Enter OK

OSP
  • 1,458
  • 1
  • 14
  • 15
4

In VS12 i just added my own shortcut because the default doesn't appear to be there.

CRTL+Shift+ALT+D

For web apps, I usually follow that with a w and enter. Enter is the big key by your right pinky.

Cory
  • 121
  • 6
2

Since the AttachTo extension is not supported by vs 2015, I suggest another one: ReAttach.

Mahmood Dehghan
  • 7,761
  • 5
  • 54
  • 71