很棒的 Visual Studio 宏
对于小型社区讨论,您使用了哪些基本的 Visual Studio 宏?
我刚刚开始了解它们,想听听你们中的一些人离不开什么。
For a small community discussion, what are some essential Visual Studio macros you use?
I just started learning about them, and want to hear what some of you can't live without.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
我在工具栏上添加了以下 3 个宏的按钮。 每个都将获取任何文件中当前选定的文本并用 google 搜索(或 MSDN-it 或拼写检查)。 为工具栏制作一个漂亮的图标以获得额外的风格点。
I add buttons on the toolbar for the following 3 macros. Each will take the currently selected text in any file and google it (or MSDN-it, or spell-check-it). Make up a nifty icon for the toolbar for extra style-points.
在输出窗口中显示构建持续时间
将此代码放入您的 EnvironmentEvents 模块中。 这会将针对解决方案的任何操作(构建、重建、清理、部署)的持续时间直接写入构建窗口。
您可以更改 IsBuild 函数来指定您想要查看此信息的操作。
Show build duration in the Output window
Put this code in your EnvironmentEvents module. This will write the duration directly to the build window for any action on a solution (build, rebuild, clean, deploy).
You can change the IsBuild function to specify the actions you want to see this information for.
关闭解决方案后显示起始页(但保持 Visual Studio 打开)
将此代码放入您的 EnvironmentEvents 模块中:
打开解决方案后隐藏起始页
将此代码放入您的 EnvironmentEvents 模块中:
当您打开解决方案时,这两者将导致您的起始页自行隐藏。 当您关闭解决方案时,起始页将返回。
Show the start page after you close a solution (but keep Visual Studio open)
Put this code in your EnvironmentEvents module:
Hide the start page after you open a solution
Put this code in your EnvironmentEvents module:
These two together will cause your Start Page to hide itself when you open a solution. When you close the solution, the Start Page comes back.
我经常使用以下鲜为人知的快捷键:
I use the following lesser-known shortcuts very often:
大纲:折叠到定义但扩展区域
您是否在一家坚持在所有内容周围都有区域的商店中工作,因此当您折叠到定义时,您看不到有代码吗?
您真正需要的是一个折叠到定义但扩展区域的宏,如下所示:
将其放入常规宏模块中,将其分配给热键,然后您的代码就回来了。
(除非......如果您与一些非常邪恶的人一起工作,他们将区域放入方法中,这将不幸地扩展这些方法。如果有人知道如何编写此代码以避免这种情况,请随意编辑。 )
Outlining: Collapse to definitions but expand regions
Are you working in one of those shops that insists on regions around everything, so that when you collapse to definitions, you can't see any code?
What you really need is a collapse-to-definitions-but-expand-regions macro, like this one:
Put this in a regular macro module, assign it to a hot key, and your code is back.
(Except...if you work with some really nefarious individuals who put regions inside methods, this will unfortunately expand those methods. If anybody knows a way to write this to avoid that, feel free to edit.)
插入 GUID,非常适合 WiX 工作,作为按钮或快捷键添加到菜单。
组织解决方案中所有 .cs 文件的使用 - 原始作者: djpark。
Insert GUID, great for WiX work, add to menu as button or as key shortcut.
Organise usings for all .cs files in a solution - Original Author: djpark.
折叠解决方案面板的所有节点,这对于大型项目非常有用:
Collapse all nodes of the Solution panel, very useful especially for big projects:
如果我要粘贴代码示例,我会使用 Jeff 的 FormatToHtml 宏到博客文章或电子邮件中。
I use Jeff's FormatToHtml macros if I'm going to be pasting a code example into a blog post or an email.
我使用双显示器,我发现 Sharon 的布局切换宏(从 1 显示器到 2 显示器布局)非常有价值。 当您需要在键入一些代码时引用网页或其他程序时,请按 Ctrl-Alt-1 切换到 Visual Studio 窗口的单显示器布局。 完成后,按 Ctrl-Alt-2 切换到两个显示器布局并恢复所有窗口。 惊人的!
http://www. invalid-city.com/sharon/2008/06/workstation-hack-visual-studio-on-2.html
I work with dual monitors, and I find Sharon's layout-switching macro (from a 1 monitor to a 2 monitor layout) totally invaluable. When you need to be referencing a web page or other program while typing a bit of code, Ctrl-Alt-1 to switch to a one monitor layout for your Visual Studio windows. Once you're done, Ctrl-Alt-2 to switch to your two monitor layout and get all your windows back. Awesome!
http://www.invisible-city.com/sharon/2008/06/workstation-hack-visual-studio-on-2.html
本身不是一个宏,但很有用:
Not a macro on its own, but useful:
我将 ctrl-shift-G 映射到一个以注册表格式生成 GUID 的宏 - 这对于编辑 IDL 很有用
I mapped ctrl-shift-G to a macro that generates a GUID in registry format - this is useful for editing IDL
我目前正在开发两个具有不同编码标准的不同项目,一个使用制表符作为行开头,另一个使用空格。 该宏将根据当前活动的环境在使用哪个标准之间切换:
I'm currently working on two different projects with different coding standards, one that uses tabs for line beginnings and another that uses spaces. This macro will toggle between which standard is used based on which environment is currently active:
我曾经在 VS 2002/2003 中使用过很多宏。 一个例子是区域创建 - 我总是喜欢将我的类划分为以下区域 - “私有成员”、“公共属性”、“公共方法”和“私有方法”。 因此,我有一个映射到快捷键的宏,可以在任何新的类文件中创建这些区域。
VS 2005/2008 中的重构支持(以及添加通用代码片段的功能)以及使用 DXCore 和 SlickEdit 等插件使我无需再创建太多宏即可工作。
I used to employ a lot of macros in VS 2002/2003. One example would be Region creation - I always like my classes to be divided into the following regions - "Private members", "Public Properties", "Public Methods" and "Private methods". So, I have a macro mapped to a shortcut key that creates these regions in any new class file.
Refactoring support in VS 2005/2008 (and the facility of adding common code snippets) as well as the use of Addins like DXCore and SlickEdit allow me to work without having to create too many macros anymore.
我不能不提这个。 它甚至还有一个视频来展示如何安装和使用它。 该宏仅允许您在解决方案资源管理器中创建嵌套文件(如 resources.resx)。
编辑:更新了链接
I couldn't let this question go without mentioning this one. It even has a video to show how to install and use it. This macro simply allows you to create the nested files in the solution explorer (like resources.resx).
Edit: Updated the link