wiliammbr's blog

Some thoughts on SharePoint and other random stuff

Debug specific W3WP in SharePoint

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:

SharePoint project with Custom Web Part

Also you need set the project Compilation as Debug, not Release.

Configurations for debugging

Once everything is okay, just deploy the solution.

Deploying a SharePoint solution

Reload the page where the Web Part is being used, just to check if the Web Application is running.

Rendered Web Part

Starting the debug session

Insert a breakpoint where you want to debug.

Simple Web Part code

Open the DEBUG menu in the topbar and click in Attach to Process.

Visual Studio's Debug Menu

A screen with the Windows processes will be opened. Check the Show processes from all users option.

Attach to Process window

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.

cd C:\Windows\System32\inetsrv
Appcmd list wp
pause

W3WP available

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.

Breakpoint was reached

If you have any doubt about the steps I’ve listed, please let me know in the comment section.
Happy coding!

References:

What is w3wp.exe?

Debugging Web Parts

2 Comments

  1. Tutorial top para quem está iniciando, ainda mais com o truque de selecionar a w3wp correta. Isso faz com que a demora diminua na hora de debugar e que o debug não se perca, que é o que muitas vezes ocorre quando selecionamos todos os processos.

  2. This comment has been removed by the author.

Leave a Reply

Your email address will not be published.

*

© 2018 wiliammbr's blog

Theme by Anders NorenUp ↑