Can I have a macro run whenever I save a file in Visual Studio 2005?

天涯浪子 提交于 2019-12-12 19:30:47

问题


When I save a file in Visual Studio 2005, I'd like to have a macro also run that updates a copyright (through a regular expression search and replace).

I'm not new to regular expressions, but I am new to VB/VBA and Visual Studio macros, so what I need help with specifically is:

  1. getting a macro to run upon save, preferably after I press CTRL-S but before it actually writes the file so that the results of the search and replace are actually saved without having to save twice

  2. calling search and replace for a regular expression from inside the VB/VBA macro


回答1:


You can record, rename, and assign a macro. Here's what I did.

  1. Menu: /Tools/Macros/Record Temporary Macro
  2. Ctrl-Shift-H - brings up the solution wide search and replace
  3. Under find options in this dialog select regular expressions. Note these will be slightly different in syntax than what you find in System.Text.RegularExpressions.
  4. Alt then F then L - file save all
  5. Open the macro editor with Menu: /tools/macros/macro explorer
  6. Right click the temporary macro to edit.
  7. In the Project Explorer of this macro right click to rename the temporary macro and save
  8. Assign to a key combination: Here’s a link to assign it to a key combination

So the idea is you can record something that is almost what you want. Then tweak it, and assign it to a key combination. Definitely try your regex first and note that there will be a dialog interrupting you if anything in your solution is read-only.



来源:https://stackoverflow.com/questions/2566746/can-i-have-a-macro-run-whenever-i-save-a-file-in-visual-studio-2005

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!