How to debug Sharepoint solution/feature through Visual studio?

13,883

Solution 1

In the WSPBuilder context menu there is an option "Attach to IIS worker process". As long as the app is loaded (generally means that you have accessed a page in the SharePoint site before trying to attach) and the code deployed in SharePoint is the same as the code you have in Visual Studio, you should be able to set breakpoints and step through the code.

Solution 2

First, you need to open up your browser and navigate to the SharePoint website in question. Then, In Visual Studio, go to Debug --> Attach to Process, and find the w3wp.exe process associated with the Sharepoint website that you want to debug. Click it (the process) and then click the Attach button. You should now be able to debug any activities associated with your SharePoint feature.

Solution 3

Sometimes it is a bit of a pain to figure out which w3wp process to attach to. Try adding the following to your code to break into the debugger:

System.Diagnostics.Debugger.Break();

Solution 4

System.Diagnostics.Debugger.Break()

Like Muhimbi suggested, this is actually very useful in certain cases. Say you want to debug custom code (e.g. feature_deactivating event) when it might be invoked with stsadm and not the browser. (for e.g. you will have to use stsadm for feature deactivation when feature is hidden in UI).When using stsadm you cannot attach to cmd.exe because that's a separate process. If you type the command and hit enter and then find its id of stsadm.exe process to attach to, its too late. In situations like these, the command above is the easist and best solution

Solution 5

I tried the steps as mentioned here

go to Debug --> Attach to Process, and find the w3wp.exe process associated with the Sharepoint website that you want to debug

But I get "Breakpoints will not be hit, no symbols have currently been loaded for this document". Should I have to register the custom deployed solution dll using GACUTIL ? Should I have to copy the PDB files at any particular location ? What am I missing here ?

Share:
13,883
pointlesspolitics
Author by

pointlesspolitics

Software Developer at Ashfieldhealthcare

Updated on June 18, 2022

Comments

  • pointlesspolitics
    pointlesspolitics almost 2 years

    Recently I tried to install a webpart through wspbuilder utility to the Sharepoint Site. I have created, built and deployed a project to the 12 hive. After that installed the solution through Cental Administration Site and activated in the site collection.

    I just wonder how can I debug the complex feature/solution ? Because both processes (build-deploy and activate) totally independent, how can I attach a process with the worker process ?

  • StuperUser
    StuperUser almost 14 years
    So using System.Diagnostics.Debugger.Break(); means you don't have to determine which w3wp.exe process is associated with the Sharepoint website? Are there anyways to determine this otherwise?
  • Kungen
    Kungen over 10 years
    Do I have to be in debug mode to use this?
  • Jeroen Ritmeijer
    Jeroen Ritmeijer over 10 years
    I believe so, but am not 100% sure. I only use it while running Debug builds.