如何在保存时配置ReSharper的代码清除? [英] How can I configure ReSharper's code cleanup on save?
问题描述
我希望将Visual Studio/ReSharper配置为在保存文件时运行代码清除".
I would love to configure Visual Studio/ReSharper to run "Code cleanup" whenever I save a file.
一个好处是仅对C#文件进行配置,因为我有时会发现对ASP.NET文件的清理在不引入错误的情况下是行不通的.
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.
推荐答案
您可以记录宏( Ctrl + E , Ctrl + C ,运行, Ctrl + S ).然后运行而不是保存.然后,您要做的就是将 CTRL + S 分配给您的宏.
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.
要删除用户交互,您将必须选择在调用代码清除"时要运行的配置文件.您可以通过进入ReSharper |选项|工具|进行代码清理,然后在用于静默清理的配置文件"下拉列表中选择配置文件.您还可以在此处创建一个自定义配置文件,以指定要对代码进行哪些更改.但在4.5中,它不允许您省略aspx页面.唯一的区别是C#和VB.Net.
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.
有用的链接: http://www.jetbrains.com/resharper/features/code_formatting .html
这篇关于如何在保存时配置ReSharper的代码清除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!