Sometimes we need to debug Visual Web Parts and Event Receivers deployed as Farm Solutions. To accomplish that is simple, just open your Visual Studio, attach to the W3WP processes and refresh your page.
Well, it’s pretty common in our daily life tasks (not so much since we all should move to the Client-side of the force) to have more than one W3WP available to attach. Usually we have one for your site, other for SharePoint Web Services, another for the SharePoint Central Admin and even more for any other Application Pool Process being used in your Server.
But if you want to attach to just one process and make Visual Studio more performatic and responsive, how can you do that?
Just follow the steps in this post!
Preparing the project
First, you have to ensure that URL for the SharePoint site is correct. You can find it in the Project Properties, in the Site URL field:
Also you need set the project Compilation as Debug, not Release.
Once everything is okay, just deploy the solution.
Reload the page where the Web Part is being used, just to check if the Web Application is running.
Starting the debug session
Insert a breakpoint where you want to debug.
Open the DEBUG menu in the topbar and click in Attach to Process.
A screen with the Windows processes will be opened. Check the Show processes from all users option.
Usually, the desired w3wp process is the first one on the list. But if you need to ensure that you are attaching to the right one, just open the Command Prompt as Administrator and paste the command below.
Appcmd list wp
Finally! Debugging your Web Part
This command will list every W3WP process and its respective name. Once you locate the right W3WP process ID, you can attach to it and start debugging without any problem.
If you have any doubt about the steps I’ve listed, please let me know in the comment section.