How to use "ReSharper.ReSharper_SilentCleanupCode" in vs2010 macro?

I am trying to create a macro that formats all modified files before saving them.

Public Module ReformatAndSave

Sub SingleFile()
    DTE.ExecuteCommand("ReSharper.ReSharper_SilentCleanupCode")
    DTE.ActiveDocument.Save()
End Sub

Sub AllFiles()
    For Each doc As Document In DTE.Documents
        If Not doc.Saved Then
            doc.Activate()
            DTE.ExecuteCommand("ReSharper.ReSharper_SilentCleanupCode")
            DTE.ActiveDocument.Save()
        End If
    Next
End Sub
End Module

      

This results in the error

HRESULT E_FAIL was returned from a call to a COM component.

It works when I use this instead:

DTE.ExecuteCommand("ReSharper.ReSharper_CleanupCode")

      

I could live with this single file solution, but choosing a profile when saving all files is annoying.

I am using ReSharper 6.1.1000.82. This error seems to be quite old: http://youtrack.jetbrains.com/issue/RSRP-179846

Is it possible to work around this error by collecting all modified files and running the CleanUpCode working command once for all files. I can manually select many files and do CleanUp on those files manually. I would like to do this automatically across all modified files when I save them.

+3


source to share


1 answer


The solution is that simple. All I had to do was replace this

DTE.ExecuteCommand("ReSharper.ReSharper_CleanupCode")

      

with this



DTE.ExecuteCommand("ReSharper_SilentCleanupCode")

      

This does not work!

DTE.ExecuteCommand("ReSharper.ReSharper_SilentCleanupCode")

      

+1


source







All Articles