每当我在Visual Studio 2005中保存文件时,都可以运行宏吗? [英] Can I have a macro run whenever I save a file in Visual Studio 2005?
问题描述
当我在Visual Studio 2005中保存文件时,我想同时运行一个用于更新版权的宏(通过正则表达式搜索和替换).
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).
我对正则表达式并不陌生,但是对VB/VBA和Visual Studio宏并不陌生,因此我需要特别的帮助:
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:
-
让宏在保存时运行,最好在我按CTRL-S之后但在它实际写入文件之前,以便实际上保存搜索和替换的结果而不必保存两次
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
从VB/VBA宏内部调用搜索并替换正则表达式
calling search and replace for a regular expression from inside the VB/VBA macro
推荐答案
您可以记录,重命名和分配宏.这就是我所做的.
You can record, rename, and assign a macro. Here's what I did.
- 菜单:/Tools/Macros/Record Temporary Macro
- Ctrl - Shift - H -提出了解决方案范围内的搜索和替换
- 在此对话框的查找"选项下,选择正则表达式.请注意,这些语法将与您在
System.Text.RegularExpressions
中找到的语法稍有不同. - Alt 然后 F 然后 L -全部保存文件
- 使用菜单:/tools/macros/macro explorer打开宏编辑器
- 右键单击临时宏进行编辑.
- 在此宏的项目资源管理器"中,右键单击以重命名临时宏并保存
- 分配密钥组合:这是一个链接,用于将其分配给密钥组合
- Menu: /Tools/Macros/Record Temporary Macro
- Ctrl-Shift-H - brings up the solution wide search and replace
- 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
. - Alt then F then L - file save all
- Open the macro editor with Menu: /tools/macros/macro explorer
- Right click the temporary macro to edit.
- In the Project Explorer of this macro right click to rename the temporary macro and save
- 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.
这篇关于每当我在Visual Studio 2005中保存文件时,都可以运行宏吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!