I know how to find unused references of a single file by right clicking on the file and selecting the "Find Usages" option. Is there any way I can see or get the list of all the unused classes or files in my project ?
-
2I have used ndepend for this in the past. – Cine Jan 10 '11 at 11:10
2 Answers
First enable "Analyze Errors In Solution" (right-click on the Resharper icon in the status bar).
Then right-click the solution node and select "Find Code issues". In the "Inspection results" tool window you can group by "Issue type" and look for "Type or type member is never used" to get all unused classes (and many more unused symbols).
A second option (after enabling "Analyze Errors In Solution") is to go to any unused class, hit Alt+Enter, select "Options for 'Type or type member ...' inspection" | Find all code issues of this type | Entire solution.

- 19,610
- 8
- 73
- 87
-
41Unused classes/Methods are coming up under "Type or type member is never used" under "Redundancies in Symbol Declarations". Not sure if this is due to version change, or I am looking at it differently. – bulltorious May 30 '12 at 17:12
-
4This hasn't returned any unused classes under any categories using Resharper 7.1 on VS2013 on Windows 8 or VS2012 on Windows 7. – Sam Jones Nov 04 '13 at 15:11
-
1At least in ReSharper 8, you don't have to enable "Analyse Errors In Solution" to get results. – Pieter van Ginkel Dec 23 '13 at 19:09
-
@SamJones: you are right.. it doesn't return any unused classes under Resharper 8.1 too... – Revious Oct 10 '14 at 12:50
-
I have a property under class with following declarion .. `public static string Answer_01 { get { return GetResourceString("Answer_01"); } }` But it is not showing under analysis errors/warnings. Is only class declaration and public methods are shown or there is way to include static property too ? – Viraj Sanghavi Oct 12 '16 at 13:53
-
3Resharper 10: This report does not show unused classes. Workaround: find some unused class in the code, and do "Find similar issues in solution" – altumano Jan 20 '17 at 14:18
-
2Still broken in Resharper 2018.1 :( Follow above workaround but if can't easily find an unused class (or method) then temporarily create one and then do _"Find similar issues in solution"_ using it – Ray Jul 03 '18 at 19:45
Solution by @ulrichc sounds perfect and works fine for small to middleweight projects in which you are not using any Dependency Injection framework such as Castle or Ninject but what if you are using DI container [Castle for instance] and you have something like the following :
public class IoC
{
private WindsorContainer _container;
private IoC()
{
_container = new WindsorContainer();
}
public static void RegisterFromAssembly(Assembly assembly, string classEndsWith, LifeTime lifeTime)
{
var lifestyle = ConvertLifeStyleType(lifeTime);
_container.Register(AllTypes.FromAssembly(assembly)
.Where(type => type.Name.EndsWith(classEndsWith))
.WithService.AllInterfaces()
.Configure(c => c.LifeStyle.Is(lifestyle))
.WithService.FirstInterface());
}
}
As you can see RegisterFromAssembly goes through all the types inside the assembly and blindly [based on the methods parameter] adds them to the container at Run-time.
You will need something like Agent Mulder plugin which provides navigation for types registered or resolved inside your containers. This again might visually [design time possibly] work but you would not really be sure unless every time you remove the unused class you run all the tests inside your application [every possible layer] to be 80% sure you are safe. Moral of the story : a class might sound unused to Resharper but it might be resurrected when you use Dependency Injection.

- 5,146
- 11
- 39
- 74
-
3Well not just DI, for any use of reflection that solution might fail. – Mohayemin Apr 20 '15 at 09:07