Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2008 / C# : How to find dead code in a project?

How do I find dead code in a Visual Studio 2008 C# project? Like unused classes, unused variables or unused resources?

like image 365
TalkingCode Avatar asked Jan 07 '10 12:01

TalkingCode


People also ask

Is Visual Studio 2008 still supported?

Visual Studio 2008 - Microsoft Lifecycle | Microsoft Learn. This browser is no longer supported. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Is Microsoft Visual C free?

A fully-featured, extensible, free IDE for creating modern applications for Android, iOS, Windows, as well as web applications and cloud services.


2 Answers

You can try FxCop, which is integrated in Visual Studio 2008 by the name of Code Analysis. You just have to right click the project file and 'Run Code Analysis'.

FxCop is an application that analyzes managed code assemblies (code that targets the .NET Framework common language runtime) and reports information about the assemblies, such as possible design, localization, performance, and security improvements.

The active rules can be configured in the Code Analysis section of the project properties. For example some rules relevant to the case in hand are present in Usage Rules and Performance Rules:

  • CA1801: Review unused parameters.
  • CA1811: Avoid uncalled private code.

And for greater flexibility you also write your own custom rules (Tutorial on writing your own Code Analysis rule).

like image 185
João Angelo Avatar answered Sep 19 '22 10:09

João Angelo


Install JetBrains ReSharper which will highlight the unused code for you.

like image 39
David M Avatar answered Sep 21 '22 10:09

David M