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

前端 未结 8 1752
时光取名叫无心
时光取名叫无心 2020-12-08 13:56

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 sometime

8条回答
  •  无人及你
    2020-12-08 14:08

    Maybe this will help someone else out in the future. I really liked the Macro idea so I adopted it. But this was not enough for me. I wanted to save all the unsaved open files at once and still get to enjoy the ReSharper cleanup function. So I came up with this Macro:

    Public Module SaveUtils
        Public Sub CleanAndSave()
            DTE.ExecuteCommand("ReSharper_SilentCleanupCode")
            DTE.ActiveDocument.Save()
        End Sub
    
        Public Sub CleanAndSaveAll()
            For i = 1 To DTE.Documents.Count
                Dim document = DTE.Documents.Item(i)
                If (Not document.Saved) Then
                    document.Activate()
                    CleanAndSave()
                End If
            Next i
        End Sub
    End Module
    

提交回复
热议问题