Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove unused functions in Visual Studio 2013

Does Visual Studio 2013 have facility for showing unused functions?

What is the best solution to removing those functions?

like image 748
Arian Avatar asked Aug 05 '14 10:08

Arian


People also ask

Where is the unused code in Visual Studio?

To find unused members with a Code Analysis Ruleset, from the Visual Studio menu select File -> New -> File… -> General -> Code Analysis Rule Set. Uncheck all the rules. There are many rules we don't care about right now – and some we probably won't ever care about.

Does linker remove unused functions?

So the linker is able to remove each individual function because it is in its own section. So enabling this for your library will allow the linker to remove unused functions from the library.


1 Answers

ReSharper can detect and highlight dead code when solution-wide analysis is enabled.

It will report some false positives, so a manual review is still needed. For instance, R# won't detect when a function is used only through reflection, and will consider it's not used. The same goes for things like IoC containers based on conventions etc.

JetBrains provides some custom attributes to decorate your code with (like [UsedImplicitly]). They guide the R# analysis engine and document your code.

like image 54
Lucas Trzesniewski Avatar answered Oct 09 '22 07:10

Lucas Trzesniewski