I am trying to build 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 an error
Error HRESULT E_FAIL has been 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 solution for a single file but choosing the profile when saving all files is annoying.
I use ReSharper 6.1.1000.82. This bug seems to be rather old: http://youtrack.jetbrains.com/issue/RSRP-179846
Is it possible to work around this bug by collecting all modified files and the execute the working CleanUpCode command once for all the files.
I can manually select many files and execute CleanUp on these files, manually. I would like to do this automatically on all modified files when saving them.
The solution is so simple.
All I had to do is replacing this
with this
This doesn’t work!