I clicked "Find Code Issues", then Resharper showed me list of unused classes and methods. But I can't find how to automatically remove all them. List of unused classes and methods contains thousands of lines, so сlicking on each line and delete method manually is not real. How to do it automatically?
I tried to use "Code Cleanup", but it doesn't remove unused classes and methods
The version of Resharper: JetBrains ReSharper 8.2.1 Full Edition Build 8.2.1000.4556 on 2014-05-19T09:12:38
Select ReSharper | Options from the main menu or press Alt+R O . Go to the cleanup profiles settings page: Code Editing | Code Cleanup | Profiles. Select which Code Cleanup profile should be applied on save and click Set as default (the default profile is also used for silent cleanup).
Clean up project references and NuGet packages in Visual Studio. Firstly, Right Click on the Project, and select “Remove Unused References”. This will bring up the “Remove Unused References” Dialog that shows the projects and all unused packages. Here, you can again choose if you want to remove them or keep it as it is ...
Go to the cleanup profiles settings page: Code Editing | Code Cleanup | Profiles. Create a new profile as described in the Create a new custom cleanup profile section. In the Selected profile settings section for the new profile, tick the Remove code redundancies checkbox.
Unfortunately Resharper does not provide this feature as it can be unsafe.
To partially automate the deletion you can try installing AutoHotkey. This program will allow you to automate the entry of hotkeys and therefore 'automate' repetitive Resharper tasks like deleting unused code detected by Code Issues.
The following script automatically goes to the next code issue and attempts to 'Safely Delete'. If this takes too long it cancels it with {Escape} as this is generally means Resharper has found a conflict or usage.
#d::
Loop {
Send !{Del}
Sleep, 500
Send {Enter}
Sleep, 1000
Send {Escape}
Sleep, 500
Send {F8}
Sleep, 500
}
Return
To use this script click on the first item under the Type Or Member is Never Used category then hit the Win-D hot key. The script will then cycle through all the issues deleting the methods which do not have conflicts. To break the loop select outside of Visual Studio & Reload the script.
If you remove the Loop & {Escape} then you can use this as a single shortcut to delete & move to the next issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With