Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I configure ReSharper's code cleanup on save?

I would love to configure Visual Studio/ReSharper to run "Code cleanup" whenever I save a file.

A bonus would be to configure this only for C# files, as I sometimes find that the cleanup on ASP.NET files does not work without introducing errors.

like image 368
Thomas Jespersen Avatar asked Jun 18 '10 17:06

Thomas Jespersen


People also ask

How do I run a code cleanup?

You can also run code cleanup across your entire project or solution. Right-click on the project or solution name in Solution Explorer, select Analyze and Code Cleanup, and then select Run Code Cleanup.

How do I clean my project on Rider?

Select one or more items (files, directories, projects, or the solution) in the Solution Explorer. Press Ctrl+E, C or choose Code | Reformat and Cleanup… from the main menu . Choose a cleanup profile as described above. Click Run to clean up code in the selected scope.

What does code cleanup do in VS?

"Code Cleanup is a new feature of Visual Studio 2019 that will automatically clean up your code file to make sure it is formatted correctly and that your coding style preferences are applied," the marketplace description says.

How do I undo a cleanup code in Visual Studio?

Use Visual Studio's Undo action (Edit | Undo menu item) to undo the cleanup after its completion. This action is available when a document is open.


1 Answers

You could record a macro(Ctrl+E, Ctrl+C,Run, Ctrl+S). Then run that instead of saving. Then all you need to do is assign CTRL+S to your macro.

Public Module RecordingModule     Sub CLEAN_AND_SAVE()     DTE.ExecuteCommand ("ReSharper.ReSharper_CleanupCode")     DTE.ActiveDocument.Save     End Sub End Module 

This method will show the code clean-up dialogue box where you will have to select Run.

To remove the user interaction you will have to select a profile to run when Code Cleanup is invoked. You can configure this by going into ReSharper | Options | Tools | Code Cleanup and selecting the profile in "Profile to use with silent clean-up" drop down. Its also here where you can create a custom profile to specify what changes to your code to make. In 4.5 however it does not allow you to omit aspx pages. The only differentiator is C# and VB.Net.

Useful link: http://www.jetbrains.com/resharper/features/code_formatting.html

like image 135
Johnno Nolan Avatar answered Oct 05 '22 17:10

Johnno Nolan