Thursday, February 3, 2011

SPDispose Check utility - Integrate with Visual Studio 2010

SPDisposeCheck utility checks whether you have disposed the unmanaged SPSite and SPWeb objects correctly or not. Its a tool that every SharePoint developer needs to have integrated in their Visual Studio boxes.

I have prepared a list of Best Practices for Disposing SharePoint objects: http://www.sharepointfix.com/2008/12/best-practices-disposing-sharepoint.html

Guidelines to integrate SPDisposeCheck with Visual Studio Solution:

1. Download the SPDisposeCheck.exe utility from: http://download.microsoft.com/download/B/4/D/B4D279A0-E159-40BF-A5E8-F49ABDBE95C7/SPDisposeCheck.msi

2. Open your Visual Studio environment and follow the steps as specified:
a. Go to Tools -> External Tools -> Add
b. Enter Title as SPDisposeCheck
c. Command : C:\Program Files (x86)\Microsoft\SharePoint Dispose Check\SPDisposeCheck.exe
d. Arguments : $(TargetName)$(TargetExt)
e. Initial Directory : $(TargetDir)
f. Check mark the Output window checkbox and
g. Click on the Ok button

See snapshot below:


3. Open your Visual Studio solution project and Build it.

4. Select Tools -> SPDisposeCheck:


5. Open the Output window and you should be able to see a set of messages like this:


6. It also shows up the errors in the Visual Studio Error Messages section as follows:

7. You can even configure additional SPDispose Check settings within Visual Studio 2010 by selecting "SharePointDispose Check" link under Tools, see snapshot below:


Let me know if it helps.