Wiki

Clone wiki

UnusedCode / Home

UnusedCode ReSharper Plugin

This is the source code of a ReSharper 6 plugin for detecting unused code within an applications (i.e. all methods which are not ultimately called by a Web application or exe.) To try the plugin, go to the Downloads page and download UnusedCodePlugin.zip, create a subfolder in your %ProgramFiles(x86)%\ReSharper\v6.x\bin\Plugins directory called something like UnusedCode, then unzip UnusedCodePlugin.zip and drop its contents into the new subfolder of Plugins. You may need to create the parent Plugins directory if this is your first plugin.

To use the plugin to detect unused code, select a file, project or the entire solution in Solution Explorer, then go to the ReSharper menu -> Tools -> Find unused code. The unused code in your selection will appear in a Find dialog or you will be shown a message saying that there is no unused code.

Test projects are ignored. Whether a project is a test project is done rather crudely by detecting whether it has references to NUnit and some other projects. I started building a user interface for specifying which projects are test projects and which are 'ultimate callers' but this is unfinished.

The plugin has problems with libraries such as Automapper which use reflection to probe properties because it thinks that a property is not used just because it is not directly called by code.

To debug the source code in Visual Studio 2010, you must run the project as administrator (which allows the plugin to be copied to the ReSharper plugin directory) and disable ReSharper by going to Tools -> Options -> Suspend. Before you start debugging please go to the properties page of the Parliament.CodeQuality.UnusedCode project and check the Build -> Output Path property. This should be pointing at C:\Program Files (x86)\JetBrains\ReSharper\v6.1\bin\plugins\UnusedCode\ or the equivalent in C:\Program Files if you're using a 32-bit machine. Also, still in the properties page of this Parliament.CodeQuality.UnusedCode, go to Debug -> Start Internal Program and ensure that the path to Visual Studio is correct. When you start debugging and Visual Studio starts running you can then resume ReSharper in the debugged process, although if you restart it in the instance you're using to debug then Visual Studio will grab a handle to the debugged DLL and you'll have to suspend and restart before you build again.

A configuration called 'Debug for Unit Testing' exists, which just outputs the plugin dll to the local bin directory, exists so that you can run ReSharper while developing for Unit Tests and therefore use ReSharper to run your unit tests.

Updated