Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / productivity / SharePoint

SharePoint Debugging: Attach all w3wp.exe processes to debugger with single click

5.00/5 (3 votes)
26 Feb 2012CPOL1 min read 22.4K  
How to attach all w3wp.exe processes to debugger with single click.

SharePoint developers know that many times they need to debug their custom SharePoint components like web parts and field types. For this purpose developer needs to attach w3wp.exe process with VS debugger again and again. We can create our own visual studio add-in which will help us to attached debugger to all w3wp processes with just one click.


Steps to create add-in:



  1. Open VS2010.
  2. Select File >> New >> Project.
  3. Select ‘Visual Studio Add-In’, you would find this under ‘Other Project Types’ >> Extensibility.
  4. This will bring wizard. Select appropriate options in wizard. Once wizard finishes use below mentioned code in
    Exec method. This code is responsible to attached w3wp.exe processes with debugger. You can use this code to attached any other process as well.

C#
foreach (EnvDTE.Process process in _applicationObject.Debugger.LocalProcesses)
{
    if (process.Name.ToLower().IndexOf("w3wp") > 0)
    {
        process.Attach();
    }
}

Compile your project and run it. This will open another instance of VS. This will automatically deploy your add-in to your local machine. You can find your add-in in tools menu. Later you can create shortcut of this item in you toolbar as well.


If you want to deploy this add-in to any other machine then you can manually copy add-in file in ‘My Documents\Visual Studio 2010\Addins\’. Once you copy this file open it in any editor and change path of assembly.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)