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:
- Open VS2010.
- Select File >> New >> Project.
- Select ‘Visual Studio Add-In’, you would find this under ‘Other Project Types’ >> Extensibility.
- 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.
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.