Welcome to MSDN Blogs Sign in | Join | Help

10 Tips to Boost Your Productivity with C# and Visual Studio 2008

Learn Key Bindings

It's an obvious and trivial thing, but the timesaving will add up, especially for those actions you perform tens or hundreds of times a day such as building and debugging.  Here are some basic bindings every Visual Studio developer should know:

  • Build: CTRL + SHIFT + B
  • Word completion: CTRL + SPACE
  • Start with debugging: F5
  • Start without debugging: CTRL + F5

Even expert Visual Studio developers can benefit by learning new bindings. Download the Visual C# 2008 Keybinding Reference Poster and hang it in your work area.

 

Generate XML Comments with GhostDoc

Instead of typing XML comments by hand, let a tool do the work for you. Although macros and snippets are reasonably effective for this, I would recommend Ghost Doc over any other solution. This free add-in uses customizable templates to generate consistent, English-readable documentation based on the current context.  To use it, right-click (or use CTRL + SHIFT + D) to document the current element.  For example:

image

 

This generates the following documentation (note GhostDoc split the property name into words and created a sentence from it):

image

 

 

Auto-Implement Properties

Take advantage of a new feature of C#: auto-implemented properties. Rather than creating a private backing field for your properties, let the compiler do it for you. The following demonstrates the syntax:

image

Use the code snippet to make this even faster.  Type prop (the shortcut for an auto-implemented property) followed by TAB TAB.  Then fill in the data type and property name:

image 

 

Refactor

The refactor feature in Visual Studio is indispensable for many tasks, especially renaming, but one productivity feature I particularly like is Encapsulate Field. If you are unable to use an auto-implemented property, declare a private field and let Visual Studio generate the Property for you.  To use this feature, right-click on the field and select Refactor > Encapsulate Field...

 

 image

The property is created for you:

image

 

 

 

Add Commands to Visual Studio 2008

Install the PowerCommands for Visual Studio 2008 to add several productivity commands such as:

  • Close all documents
  • Copy and paste a class (automatically renames)
  • Remove and sort using statements project-wide
  • Copy and paste references (including a project reference)

Install the Team Foundation Server Power Tools to add several TFS productivity commands such as:

  • Find in source control
  • Open source folder in Windows Explorer
  • Work item templates (can be used to set values on multiple work items at once)

Add your own productivity commands.  For example, to add Reflector so it automatically opens on the current project.

  • Select Tools > External Tools
  • Click Add
  • Name it Reflector and browse to the executable
  • Enter $(TargetPath) for the Arguments

 

Speed up Compilation with Project Configuration

You may build tens of times during a programming session, so don't enable anything that isn't absolute necessary such as code analysis and XML documentation.  Develop in Debug configuration, and switch to Release configuration just before check-in to run code analysis and generate XML documentation. In a large solution I recently worked on, this shaved a minute off compilation time.

The following shows code analysis disabled in Debug configuration:

 

 

 image

The following shows code analysis enabled in Release configuration:

image 

 

Let Visual Studio Generate Unit Test Code

Although it can't fully automate unit testing yet (check out Pex), Visual Studio does a good job of generating positive unit test code to give you a jump start.  To use this feature, right-click on an element you would like to test and select Create Unit Tests... 

image

Visual Studio generates the following test method:

image

 

Use Interface-Driven-Design

You probably never thought of an interface as a productivity feature, but it can be if your development process is driven by contracts instead of implementation.  Let me illustrate with a simplified example.  One developer owns the business layer and another developer owns the data access layer, and they need to agree on how to communicate to implement a new feature.  In some business object designs, business components will instantiate data components (or call a static method).  This is a problem from a design standpoint because the two become tightly coupled.  It is also a problem from the productivity standpoint because the business layer developer becomes dependent on the data access layer developer's implementation.  Interface-driven design (IDD) solves this issue.

Rather than the business component developer waiting on the data component developer, they meet to design and implement the interface.  Both developers are then free to go their separate ways and implement the components in parallel.  IDD also enables the business developer to mock the data access component, thereby removing any scheduling dependencies.  The following illustrates the design:     

image

Make a Mockery of Dependencies

Different developers may own layers or features that your component is dependent on, but don't let that slow you down.  Suppose you are responsible for the business layer which depends on the data access layer which in turn depends on database tables and stored procedures. Rather than waiting for dependent layers to be completed, mock the data access layer so you can implement and unit test the business layer. By the way, you should be using mocks anyway; otherwise your unit tests are more than likely integration tests.  I recommend Rhino Mocks.

Here is a sample unit test with mocks:

image

Data Drive Unit Tests

If you have a unit test that multiple inputs to fully test, you could write a test method for every possible combination, but data-driven unit tests are more efficient.  When the unit test is run, it loads data from a table and calls the unit test for each row.  You can access the data in the current row using the TestContext.DataRow property.

image

Once the test completes, you can view the results:

image

Published Sunday, March 23, 2008 12:48 PM by johnwpowell
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: 10 Tips to Boost Your Productivity with C# and Visual Studio 2008

Monday, March 24, 2008 9:57 AM by Frank W Holt Jr

Great blog! I especially like the 'Data Driven Testing' piece. I'm getting into this area and have been running a script for each test to prepare the data. I'll give this a shot. Thanks.

# 10 Tips to Boost Your Productivity with C# and Visual Studio 2008

Monday, March 24, 2008 11:27 AM by Hosam Kamel

Some tips posted by John W Powell about how to increase your development productivity using Visual Studio

# re: 10 Tips to Boost Your Productivity with C# and Visual Studio 2008

Monday, March 24, 2008 12:33 PM by Uwe Keim

More tips:

11. Use ReSharper (www.jetbrains.com)

12. Use SonicFileFinder (sonicfilefinder.jens-schaller.de - from the co-worker of the GhostDoc author)

# re: 10 Tips to Boost Your Productivity with C# and Visual Studio 2008

Monday, March 24, 2008 9:26 PM by John Powell

Thanks for the feedback!

Unfortunately ReSharper isn't available for Visual Studio 2008 (yet)

# re: 10 Tips to Boost Your Productivity with C# and Visual Studio 2008

Monday, March 24, 2008 10:00 PM by Morgan Cheng

This post is really helpful!!!

# re: 10 Tips to Boost Your Productivity with C# and Visual Studio 2008

Wednesday, March 26, 2008 12:02 PM by Karl Agius

Excellent advice and references, thanks!!!

# re: 10 Tips to Boost Your Productivity with C# and Visual Studio 2008

Wednesday, March 26, 2008 3:30 PM by Derik Whittaker

Let Visual Studio Generate Unit Test Code -- Makes my skin crawl.  

Why, because if you allow test to be generated you may not fully understand the intent of the test.  Making it almost useless.

Don't get me wrong, having generated tests is better than NO tests at all, but this is the lazy mans version of testing if you ask me.

http://devlicio.us/blogs/derik_whittaker/archive/2008/03/26/39701.aspx

# March 28th Links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Visual Studio, Silverlight, .NET

Friday, March 28, 2008 4:08 AM by ScottGu's Blog

Here is the latest in my link-listing series .  Also check out my ASP.NET Tips, Tricks and Tutorials

# March 28th Links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Visual Studio, Silverlight, .NET

Friday, March 28, 2008 4:16 AM by BusinessRx Reading List

Here is the latest in my link-listing series .  Also check out my ASP.NET Tips, Tricks and Tutorials

# March 28th Links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Visual Studio, Silverlight, .NET

Friday, March 28, 2008 4:52 AM by Mirrored Blogs

Here is the latest in my link-listing series .  Also check out my ASP.NET Tips, Tricks and Tutorials

# re: 10 Tips to Boost Your Productivity with C# and Visual Studio 2008

Friday, March 28, 2008 5:32 AM by Hüseyin Tüfekçilerli

To generate XML Comments for fields, methods, properties, etc. you can tap forward slash 3 times while your cursor was just before the declaration line. Like this (| represents your cursor):

|

public bool IsCool { get; set; }

->

///|

public bool IsCool { get; set; }

->

/// <summary>

/// |

/// </summary>

public bool IsCool { get; set; }

This is built-in to Visual Studio.

# re: 10 Tips to Boost Your Productivity with C# and Visual Studio 2008

Friday, March 28, 2008 10:26 AM by Laurent Duveau

Very interesting.

Regarding the prop snippet I reported a problem on Connect:

http://weblogs.asp.net/lduveau/archive/2008/03/22/code-snippets-not-versioned-according-to-vs2008-multi-targeting.aspx

# re: 10 Tips to Boost Your Productivity with C# and Visual Studio 2008

Friday, March 28, 2008 1:35 PM by Ricardo

The prop snippet in VS 2008 is not very efficient, at least not as good as the one in 2005, which would actually generate the get and set bodies.  I ended up copying the one from 2005 to 2008 and that's the one I use!

# 3月28日链接篇: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Visual Studio, Silverlight, .NET

Saturday, March 29, 2008 1:33 AM by Joycode@Ab110.com

【原文地址】 March 28th Links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Visual Studio, Silverlight, .NET 【原文发表日期

# re: 10 Tips to Boost Your Productivity with C# and Visual Studio 2008

Saturday, March 29, 2008 12:13 PM by Kyralessa

Most of those tips look handy (though most I already knew), but that GhostDoc thing looks awful.  Auto-generated "documentation" that documents IsCool with "Gets or sets a value indicating whether this instance is cool" is worse than useless.  It's worse because it's a time-waster: You consult the documentation for help, and all it does is waste your time telling you something you already knew from the name.

Better to have *no* documentation than to have reams of pointless "documentation" like that.

# re: 10 Tips to Boost Your Productivity with C# and Visual Studio 2008

Saturday, March 29, 2008 7:08 PM by dthomelin

Boosting productivity is first a good help,

I have visual studio 2008 with MSDN Help and I found that source selection that is available when installing MSDN help is irelevant.

One need when developping web aspx for example to be able to restrict full text search within help to a few Sources like C# or Source System

Currently search is giving result for a search througout tons of sources like sharepoint, windows fundation,

widows forms or mobile meaning that help search is awfull

is there a way to choses the specific sources that you want to search.

Don say filter, it works only for keyword list.

# 转载一篇VS2008的小技巧,提高工作效率必备啊!

Sunday, March 30, 2008 9:34 PM by Jack Niu

# Nice plugins : PowerCommands for Visual Studio 2008

Sunday, March 30, 2008 11:19 PM by Ronald Rajagukguk

Kemaren setelah usai diajak mengabdi kepada negara oleh bang naren , maka gua melakukan blogwalking di

# re: 10 Tips to Boost Your Productivity with C# and Visual Studio 2008

Monday, March 31, 2008 10:27 AM by tourist.Tam

Plenty of whinny in the comment .... :(

Anyway, thanks a lot for the few tricks that I had no knowledge of. ;)

Specially the mockery (wording that I wouldn't have though about to describe that).

Tam

# re: 10 Tips to Boost Your Productivity with C# and Visual Studio 2008

Monday, March 31, 2008 1:11 PM by Chris Staley

ReSharper does support VS 2008.  3.1 (the current release version) will handle all of your C# 2.0 needs.  RS 4.0 is still in alpha/beta/whatever, but the nightly builds (http://www.jetbrains.net/confluence/display/ReSharper/ReSharper+4.0+Nightly+Builds) have proven useful in the interim for working with the new C# 3.0 language enhancements.

# 10 Tips to Boost Your Productivity with C# and Visual Studio 2008

Wednesday, April 02, 2008 10:45 PM by AllenWang.NET

JohnWPowell分享了在使用C#和VS2008时如何提高生产力的几个技巧和诀窍。

http://blogs.msdn.com/johnwpowell/archive/2008/03/23...

# 本周ASP.NET英文技术文章推荐[03/23 - 04/05]:C#、Visual Studio、MVC、死锁、Web 2.0 API、jQuery、IIS7、FileUpload

Friday, April 04, 2008 11:28 PM by Dflying Chen

摘要本期共有9篇文章:提高C#和VisualStudio2008生产力的10个技巧ASP.NETMVCAction过滤器:缓存和压缩程序停止工作及其解决方法:第一部分:死锁调用D...

# 10 Tips to Boost Your Productivity with C# and Visual Studio 2008 -- John W Powell

Saturday, April 05, 2008 4:44 AM by 晓江工作室

LearnKeyBindings

It'sanobviousandtrivialthing,butthetimesavingwilladdup,especiallyfo...

# 提升C#和Visual Studio生产率的10个提示

Saturday, April 05, 2008 8:15 PM by dreamliner

明显而又简单,但是节省时间,尤其是对于那些你每天都要执行上百次的操作,例如构建和调试。下面是一些每个Visual Studio都应该知道的一些基本的快捷键:

# 【收藏】本周ASP.NET英文技术文章推荐[03/23 - 04/05]:C#、Visual Studio、MVC、死锁、Web 2.0 API、jQuery、IIS7、FileUpload

Thursday, April 10, 2008 3:16 AM by Jacky_Xu

摘要

本期共有9篇文章: 提高C#和VisualStudio2008生产力的10个技巧

ASP.NETMVCAction过滤器:缓存和压缩

程序停止工作及其解决方法:第一部分...

# re: 10 Tips to Boost Your Productivity with C# and Visual Studio 2008

Saturday, May 10, 2008 5:53 PM by Scott Bellware

So Microsoft lets the community smoke clear from the last time a softie tried to sell the idea of reverse-engineering tests from code, and we're right back to where we were a couple of years ago.  Zero progress.  Zero growth.  And Microsoft still trying to take advantage of its customers by working to convince them to use features that reduce customers' success potential.

Is it so hard to provide guidance based on practices that yield the greatest results rather than guidance that merely justifies the investment you've made in questionable features?

The crisis of quality and consciousness continues in the Microsoft sphere of influence and coercion.

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker