11 Visual Studio 2005 IDE Tips and Tricks to Make You a More Productive Developer

Visual Studio 2005 IDE相关的11个提高开发效率的技巧
英文原创来源于:
http://www.chinhdo.com/chinh/blog/20070920/top-11-visual-studio-2005-ide-tips-and-tricks-to-make-you-a-more-productive-developer/

Here are my top 11 tips and tricks for getting things done faster with the Visual Studio 2005 IDE (without using third-party add-ins or upgrading hardware… that’s another article). Yes, some of these tips and tricks may fall into the “obvious” category, but I think they are worth repeating. I continue to see too many .NET developers not taking advantage of even the basic time-saving techniques.

I work mostly with C# so some of these tips may not apply to, or work differently with other Visual Studio languages such as Visual Basic.NET.

当用Visual Studio 2005 IDE开发时,有11个技巧可以提高你的开发效率(不必使用三方插件或者升级硬件...那些方法另当别论)。当然,其中一些技巧可能已经众所周知,但我想还是要老调重弹。我还是看到太多的开发人员没有采用最基本的节省时间的技术。

(1) Express Yourself with Regular Expressions

Regular Expressions is a powerful and portable text search/replace/transformation language. Learning basic Regular Expressions will immediately make you a more productive developer/power user. Regular Expressions is supported in Visual Studio’s various Search/Replace dialogs. Any Regular Expressions skill you learn will also be useful in numerous other applications and settings: other text editors, unix shell/egrep, PowerShell, input validation, and Google search (heh, just kidding on that last item).

正则表达式是一种强大和方便的文本搜索,替换,转换的语言。学好正则表达式会使你很快的提升自己的开发速度。Visual Studio中的查找,替换对话框支持正则表达式。正则表达式在许多别的应用和配置场合也大量地用到:其他的文本编辑器,Unix shell/egrep,PowerShell,输入验证,和Google搜索。
你也可以通过Regex类使用带有宏和自动化的正则表达式。
这里举个例子来演示如何在Visual Studio中使用正则表达式来节省时间。假设,你已经在查询工具中写好并测试了SQL语句,现在想在C#类中把SQL语句赋给字符串变量。看看如何来做:
首先,粘贴SQL语句到编辑器中。确保删除sql语句左边的所有不想要的字符(选中SQL语句,之后按上几次SHIFT-Tab来删除多余的空白字符):
You can also use Regular Expressions with macros and automation via the Regex class.

Here’s an example of how you can save time with Regular Expressions in Visual Studio. Say, you just wrote and tested a SQL in a Query Tool and you want to turn it into a  string variable in your C# class? Here’s how:

First, paste the SQL text into the editor. Make sure to remove any unwanted indentation on the left side of the text (SHIFT-Tab):

Regular Expressions Example - 1 

Select a,b,
,c
,d
,e
from
table

Then hit CTRL+H to bring up the Find and Replace Dialog and fill it out like this:
然后按CTRL+H 打开查找和替换对话框,并按下图填写:

Regular Expressions Example - 2 


Choose Replace All. Fix a couple of lines, sit back and admire your beautiful work:
选择“全部替换”。更新了如下所示的一些行。

Regular Expressions Example - 3 
+"Select a,b,"
+",c"
+",d"
+",e"
+"from"
+"table"

这是怎么回事呢?“Find what”表达式匹配各行中的内容并给内容一个编号的标签。“Replace with”表达式用标签(\1)替换各行。
Explanation? Basically, the “Find what” expression above matches the content of each line and give it a numbered “tag”. The “Replace with” expression then replaces each line with the first tagged value (\1), wrapped around in + ” “. Click the fly-out (triangle) button next to each box to display a cheat-sheet of frequently used expressions. Oh, and don’t worry about the “+” string concatenations in the example, the compiler knows to optimize that syntax.

Once you’ve created a few Search/Replace expressions like the above, create macros out of them and assign to shortcuts.

Here are some of the Regex transformations I use most often when writing code:

  • Surrounds each line with (example above).
  • Transform a list of values separated by newlines into a coma-delimited list (used in array initializers or SQL where clause).
  • Put double quotes around each value in a coma-separated list.

Tools to help you write/test Regular Expressions:

(2) Take (Keyboard) Shortcuts

Using keyboard shortcuts is the best way to get things done faster in Visual Studio (and most other computer applications for that matter).

Below are my favorite Visual Studio keyboard shortcuts (VB.NET. I am leaving out the really obvious ones like F5).

  • CTRL+ALT+L: View Solution Explorer. I use Auto Hide for all of my tool windows to maximize screen real estate. Whenever I need to open the Solution Explorer, it’s just a shortcut away. Related shortcuts: CTRL+ALT+X (Toolbox), F4 (Properties), CTRL+ALT+O (Output), CTRL+\, E (Error List), CTRL+\, T (Task List).
  • F12: Go to definition of a variable, object, or function.
  • SHIFT+F12: Find all references of a function or variable.
  • F7: Toggle between Designer and Source views.
  • CTRL+PgDn: Toggle between Design and Source View in HTML editor.
  • F10: Debug - step over. Related debugging shortcuts: F5 (debug - start), F11 (debug - step into), SHIFT-F11 (debug - step out), CTRL-F10 (debug - run to cursor). F9 (toggle breakpoint).
  • CTRL+D or CTRL+/: Find combo (see section on Find Combo below).
  • CTRL+M, O: Collapse to Definitions. This is usually the first thing I do when opening up a new class.
  • CTRL+K, CTRL+C: Comment block. CTRL+K, CTRL-U (uncomment selected block).
  • CTRL+-: Go back to the previous location in the navigation history.
  • ALT+B, B: Build Solution. Related shortcuts: ALT+B, U (build selected Project), ALT+B, R (rebuild Solution).
  • CTRL+ALT+Down Arrow: Show dropdown of currently open files. Type the first few letters of the file you want to select.
  • CTRL+K, CTRL+D: Format code.
  • CTRL+L: Delete entire line.
  • CTRL+G: Go to line number. This is useful when you are looking at an exception stack trace and want to go to the offending line number.
  • SHIFT+ALT+Enter: Toggle full screen mode. This is especially useful if you have a small monitor. Since I upgraded to dual 17″ monitors, I no longer needed to use full screen mode.
  • CTRL+K, X: Insert “surrounds with” code snippet. See Snippets tip below.
  • CTRL+B, T: Toggle bookmark. Related: CTRL+B, N (next bookmark), CTRL+B, P (prev bookmark).

The complete list of default shortcuts is available from VS 2005 Documentation. You can also download/print reference posters from Microsoft: C# Keyboard Reference Poster, VB.NET Keyboard Reference Poster.

(3) Make New Shortcuts

There is something you do a lot in Visual Studio and there is no shortcut for it? Create one. Here’s how:

  • Choose Tools/Options and select Environment/Keyboard.
  • Type in something into “Show commands containing” to get a list of matching commands. If there is already a shortcut for the selected command, it’ll be displayed in “Shortcuts for selected command”.
  • To assign a new shortcut to the selected command, put the cursor in “Press shortcut keys” and press the shortcut key or key combinations desired.

Visual Studio Options - Keyboard 

Have a custom Macro that you run often? Assign it to a keyboard shortcut. Here are some of my custom keyboard shortcuts:

  • CTRL+Num, T: Show the Test View.
  • CTRL+Num, D: Start debugging the selected Unit Test in Test View.
  • CTRL+’, L: “Collapse all in Solution Explorer ” macro (see Macros section below).
  • CTRL+’, S: “Surrounds each line with” Macro.
  • CTRL+’, C: Compare with previous Source Control version.

(4) Use Code Snippets

Save time typing repetitive code by using Code Snippets. There are two types of Snippets in Visual Studio 2005: Exansion and SurroundsWith. To use Expansion Snippets, type the Snippet shortcut (not to be confused with keyboard shortcuts), and press Tab twice.

For example, the “for” Snippet is an Expansion Snippet. To use it, type “for”…

'for' Expansion Snippet Step 1 

Then press Tab, Tab:

'for' Expansion Snippet Step 2 

I find SurroundsWith Snippets more useful though. An example SurroundsWith Snippet is “#region”. First, select a block of code:

SurroundsWith Snippet Step 1 

Then, type CTRL+K, CTRL+S and “#re“:

SurroundsWith Snippet Step 2 

Then hit Enter:

SurroundsWith Snippet Step 3 

Here are my favorite Snippets:

  • #region: Regions is a great way to organize your code.
  • using: If you create an IDisposable object, you should use the “using” pattern. In addition to the basic “using” Snippet, I also created several variations for TransactionScope, and IDataReader.
  • try/catch
  • {}
  • /// <summary>$end$</summary>

More info:

(5) State Your Preferences

Find yourself constantly switching to the Design view every time you create/open an ASPX page? Cannot locate your current file in the Solution Explorer? Easy… just change the right settings and never think about it again.

Here are the some settings in Visual Studio that can save you time:

  • Open HTML pages in Source View: Tools/Options/HTML Designer/Start pages in.
  • Track the current file in Solution Explorer: Tools/Options/Projects and Solutions/Track Active Item in Solution Explorer.
  • Change the Start page or get rid of it: Tools/Options/Environment/Startup.
  • Change the default font-size to a smaller size so you can see more code. My editor font setting is ProFontWindows at size 9.
  • Turn of animations: Uncheck Tools/Options/Environment/Animate environment tools.

(6) “Attach to Process” to Start Debugging ASP.NET

Most ASP.NET developers use the standard F5 (Debug/Start Debugging) to start debugging from Visual Studio. However, there is a much faster way to start debugging if you already have an instance of your web application running. Just attach to it instead:

  • Choose Debug/Attach to Process.
  • Select the “aspnet_wp.exe” process and choose Attach.

Or, for keyboarders:

  • ALT+D, P, “as“, Enter.

Debugging this way is faster because you skip the often-lengthy compilation step, and you don’t have to navigate from the start page to the actual page that you want to debug.

(7) Stop Conditionally (Conditional Breakpoints)

How often have you found yourself repeatedly stepping through a loop while debugging, waiting to get to a specific loop value (because the bug only occurs with that specific value)? With Conditional Breakpoints, you don’t have to do that. Just set a Breakpoint Condition.

Set the Breakpoint. Right click on the Breakpoint indicator (red circle), and choose Condition:

Breakpoint Condition Step 1 

Set the condition (any valid C# expression):

Breakpoint Condition Step 2 

Another debugging productivity trick I use is to override ToString() to return a useful summary of your objects. The Debugger uses the value returned by ToString in various Debug windows such as Watch Window. You can also use the DebuggerDisplay attribute.

(8) Employ Task List Tokens

Use Task List tokens such as TODO and HACK to quickly mark incomplete code or code that requires further attention. This allows you to keep flowing and skip over the details, but at the same time ensures that you will not forget to go back and finish up.

A shortcoming with Visual Studio 2005’s Task List is that it only shows the items in the current file. You can get around this by using the Find in Files feature and search for “// TODO”.

(9) Go Directly to Any File with the Find Combo Box

This is the Find dropdown that is on the Standard Toolbar, not the Find dialog. Use the shortcut CTRL+D to activate the Find dropdown in normal mode. Use CTRL+/ to activate the Find dropdown in command mode (with “>” prepended… this doesn’t work sometimes for me).

Find Combo 

To quickly go to a file, type CTRL+D, >open  <start of file name>. Intellisense works here just like in the Command Window. “of” (short for “open file”) can be used instead of open. Compare this with opening Solution Explorer, expand the correct folder/project, and visually hunt for the file you need.

With the Find Combo, you can also execute commands, macros, find text, etc. More info:

(10) Type Ahead (Incremental Search) in Lists

(10)在列表项中输入名称的头字母(增量搜索)
在许多VS列表项中都可以使用增量搜索,比如解决方案管理器,活动文件组合框,添加引用,类视图,附加到进程,测试视图,等。
Type-ahead search works in many Visual Studio lists such as Solution Explorer, Active Files Combo (CTRL+ALT+Down Arrow), Add References, Class View, Attach to Process, Test View, etc.

上图中,如输入字母L,自动选中Language, 输入T,自动选中Transaction.
To see how it works, it’s best to try it yourself. Open the Solution Explorer and start typing the first few letters of a visible file.

(11) Automate with Macros and Visual Studio Automation

(11)用宏和VS自动化工具实现自动化
使用宏有可能显著的提高开发效率,但是前期需要投入大部分时间。
对许多开发人员来说,使用宏最有效的途径是搜集和使用或者定制别人的宏。
如果你想从写自己的宏开始,首先得熟悉宏录制(快捷键:CTRL+SHIFT+R,见下图
I save this for last because I think macros and Automation have the potential to give you the biggest productivity booster, but also require the most initial time investment.

For many developers, the most effective way to take advantage of macros is to find and use or customize someone else’s macros.

If you want to get started with writing your own macros, the first feature you should get familiarize yourself with is the Macro Recording feature (shortcut CTRL+SHIFT+R).


For more info:(更多内容请参见:)

Here are some useful macros for you to start with:(你可以参考以下有用的资源:)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


引言 本文从Linux小白的视角, 在CentOS 7.x服务器上搭建一个Nginx-Powered AspNet Core Web准生产应用。 在开始之前,我们还是重温一下部署原理,正如你所常见的.Net Core 部署图: 在Linux上部署.Net Core App最好的方式是在Linux机器
引言: 多线程编程/异步编程非常复杂,有很多概念和工具需要去学习,贴心的.NET提供Task线程包装类和await/async异步编程语法糖简化了异步编程方式。 相信很多开发者都看到如下异步编程实践原则: 遵守以上冷冰冰的②③条的原则,可保证异步程序按照预期状态正常运作;我们在各大编程论坛常看到违背
一. 宏观概念 ASP.NET Core Middleware是在应用程序处理管道pipeline中用于处理请求和操作响应的组件。 每个组件是pipeline 中的一环。 自行决定是否将请求传递给下一个组件 在处理管道的下个组件执行之前和之后执行业务逻辑 二. 特性和行为 ASP.NET Core处
背景 在.Net和C#中运行异步代码相当简单,因为我们有时候需要取消正在进行的异步操作,通过本文,可以掌握 通过CancellationToken取消任务(包括non-cancellable任务)。 Task&#160;表示无返回值的异步操作, 泛型版本Task&lt;TResult&gt;表示有返
HTTP基本认证 在HTTP中,HTTP基本认证(Basic Authentication)是一种允许网页浏览器或其他客户端程序以(用户名:口令) 请求资源的身份验证方式,不要求cookie,session identifier、login page等标记或载体。 - 所有浏览器据支持HTTP基本认
1.Linq 执行多列排序 OrderBy的意义是按照指定顺序排序,连续两次OrderBy,后面一个有可能会打乱前面一个的排序顺序,可能与预期不符。 要实现sql中的order by word,name类似效果; LINQ 有ThenBy可以紧接使用, ThenBy记住原本排序的值,然后再排其他值,
ASP.NET Core 核心特性:开源、跨平台、高性能是其决战JAVA的必胜法宝,最引人关注的跨平台特性 到底是怎么实现? &#xA; 本文分Unix、Windows剖析跨平台内幕,读完让你大呼过瘾。
前导 Asynchronous programming Model(APM)异步编程模型以BeginMethod(...) 和 EndMethod(...)结对出现。 IAsyncResult BeginGetResponse(AsyncCallback callback, object state
引言 最近在公司开发了一个项目,项目部署架构图如下: 思路 如图中文本所述,公司大数据集群不允许直接访问外网,需要一个网关服务器代理请求,本处服务器A就是边缘代理服务器的作用。 通常技术人员最快捷的思路是在服务器A上部署IISʺpplication Request Routing Module组件
作为一枚后端程序狗,项目实践常遇到定时任务的工作,最容易想到的的思路就是利用Windows计划任务/wndows service程序/Crontab程序等主机方法在主机上部署定时任务程序/脚本。 但是很多时候,若使用的是共享主机或者受控主机,这些主机不允许你私自安装exe程序、Windows服务程序
引言 熟悉TPL Dataflow博文的朋友可能记得这是个单体程序,使用TPL Dataflow 处理工作流任务, 在使用Docker部署的过程中, 有一个问题一直无法回避: 在单体程序部署的瞬间(服务不可用)会有少量流量无法处理;更糟糕的情况下,迭代部署的这个版本有问题,上线后无法运作, 更多的流
合格的web后端程序员,除搬砖技能,还必须会给各种web服务器配置Https,本文结合ASP.NET Core部署模型聊一聊启用Https的方式。 温故知新 目前常见的Http请求明文传输,请求可能被篡改,访问的站点可能被伪造。 HTTPS是HTTP加上TLS/SSL协议构建的可进行加密传输、身份认
长话短说 前文《解剖HttpClientFactory,自由扩展HttpMessageHandler》主要讲如何为HttpClientFactory自定义HttpMessageHandler组件, 现在来完成课后的小作业: 将重点日志字段显示到Nlog的LayoutRenderer上。 本文实现一个
引言问题 作为资深老鸟,有事没事,出去面试;找准差距、定位价值。 面试必谈哈希, Q1:什么是哈希? Q2:哈希为什么快? Q3:你是怎么理解哈希算法利用空间换取时间的? Q4:你是怎么解决哈希冲突的? Q5:你有实际用写过哈希算法吗? 知识储备 哈希(也叫散列)是一种查找算法(可用于插入),哈希算
前言 如题,有感于博客园最近多次翻车,感觉像胡子眉毛一把抓, 定位不了生产环境的问题。 抛开流程问题,思考在生产环境中如何做故障排除,&#160;发现博客园里面这方面的文章比较少。 .Net 本身是提供了sos.dll工具帮助我们在生产中故障排除,通过提供有关内部公共语言运行时(CLR)环境的信息,
.NET程序是基于.NET Framework、.NET Core、Mono、【.NET实现】开发和运行的 ,定义以上【.NET实现】的标准规范称为.NET Standard .NET Standard .NET标准是一组API集合,由上层三种【.NET实现】的Basic Class Library
长话短说 上个月公司上线了一个物联网数据科学项目,我主要负责前端接受物联网事件,并提供 参数下载。 webapp 部署在Azure云上,参数使用Azure SQL Server存储。 最近从灰度测试转向全量部署之后,日志时常收到: SQL Session超限报错。 排查 我在Azure上使用的是 S
临近年关,搜狗,360浏览器出现页面无法成功跳转,同域Cookie丢失? 也许是服务端 SameSite惹的祸。&#xA;本文揭示由于Chrome低版本内核不识别 SameSite= None, 引发的单点登录故障。
本文聊一聊TraceID的作用和一般组成,衍生出ASP. NETCore 单体和分布式程序中 TraceId 的使用方式
通过给 HttpClint请求的日志增加 TraceId,解锁自定义扩展 HttpClientFacroty 的姿势