SPDisposeCheck in Visual Studio

One of the comments I have gotten from the latest USP Journal issue is that running the SPDisposeCheck is awkward because you have to do it via command line.

That’s not necessarily true, there’s an easier way.

Visual Studio supports external tools, allowing you to run command line tools and get the output in the Visual Studio output window. Since SPDisposeCheck is a command line tool, that’s a perfect match.

To set up SPDisposeCheck as an external tool in Visual Studio, go to the Tools->External Tools menu option. Click Add and fill in the form by browsing to the SPDisposeCheck.exe file (usually in C:\Program Files\Microsoft\SharePoint Dispose Check\SPDisposeCheck.exe) and select TargetPath in the Arguments field drop-down, as shown below.

Figure 1

Finally, ensure that the Use Output window checkbox is checked, and hit OK.

Check your Tools menu, and you should have a new option for SPDisposeCheck. Selecting this option will run SPDisposeCheck and output the results from checking your DLL or EXE in the Output window of Visual Studio.

Figure 3

If you want a faster way of accessing SPDisposeCheck, add an & in front of one of the letters in the Title field. That letter now becomes the shortcut key for accessing SPDisposeCheck from the Tools menu. For example, if you set the title to SPDisposeC&heck;, you can run the command using ALT+T (for Tools menu) and then hit H. Sadly, H is the only letter in SPDisposeCheck not already occupied by other menu commands, but you are, of course, free to set the title to anything you like, such as Xyzzy and use X, Y, or Z as the quick-key 🙂

Figure 2


Found this article valuable? Want to show your appreciation? Here are some options:

a) Click on the banners anywhere on the site to visit my blog's sponsors. They are all hand-picked and are selected based on providing great products and services to the SharePoint community.

b) Donate Bitcoins! I love Bitcoins, and you can donate if you'd like by clicking the button below.

c) Spread the word! Below, you should find links to sharing this article on your favorite social media sites. I'm an attention junkie, so sharing is caring in my book!

Pin It

Published by

Bjørn Furuknap

I previously did SharePoint. These days, I try new things to see where I can find the passion. If you have great ideas, cool projects, or is in general an awesome person, get in touch and we might find out together.

4 thoughts on “SPDisposeCheck in Visual Studio”

  1. You can also set it up as a post-build event. I use the following:

    "%ProgramFiles%\Microsoft\SharePoint Dispose Check\SPDisposeCheck.exe" $(TargetPath)

    The build will now fail if any errors are found!

Leave a Reply

Your email address will not be published.