Priyang Patel’s Weblog


Increase your productivity using visual studio 2008

Posted in Visual Studio Tips and Tricks by priyangpatel on June 3, 2008

Basic Building Commands:

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

Download the Visual C# 2008 Keybinding Reference Poster.

Use GhostDoc to create XML Comments

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:


This generates the following documentation:

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:

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:

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…

The property is created for you:

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:

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…


Visual Studio generates the following test method:

Find files faster with Find Combo Box !!!!

Posted in Visual Studio Tips and Tricks by priyangpatel on May 30, 2008

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).


To quickly go to a file, type CTRL+D, >open . 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.

Start debugging faster by "Attach to Process"

Posted in Visual Studio Tips and Tricks by priyangpatel on May 30, 2008

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.

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.

Enjoy Code Snippet with Visual Studio 2008 !!!!!!!

Posted in Visual Studio Tips and Tricks by priyangpatel on May 27, 2008

If you know what is “Code Snippet” ? & how to use it? with visual studio 2005.

But now if you are using Visual Studio 2008 then you won’t find it. Don’t worry it is not removed from visual studio, you can still use it.

Copy and paste or create your snippet file to following address of your computer:

My Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets

It’s done, just go to visual studio and write down snippet name and press tab.

Cheers!!!!

Highly customizable CAPTCHA verification. Its Free !!!

Posted in Visual Studio Tips and Tricks by priyangpatel on April 7, 2008

Learn and defend your ASP.NET sites against evil bots with this free web control that provides instant, highly customizable CAPTCHA verification.

Its Free !!!

Visual studio Posters!!!!! Very useful

Posted in Visual Studio Tips and Tricks by priyangpatel on April 2, 2008

Hear is the interesting blog post containing links to posters about Microsoft technologies.

It lists posters for Visual studio 2008!!! also with C# and VB. Also it contains posters for developers , business apps and professional apps also.

 To get it — Click Here

Visual studio Posters!!!!! Very useful

Posted in Visual Studio Tips and Tricks by priyangpatel on April 2, 2008

Hear is the interesting blog post containing links to posters about Microsoft technologies.

It lists posters for Visual studio 2008!!! also with C# and VB. Also it contains posters for developers , business apps and professional apps also.

To get it — Click Here

PowerCommands for Visual Studio 2008

Posted in Visual Studio Tips and Tricks by priyangpatel on March 25, 2008

PowerCommands is a set of useful extensions for the Visual Studio 2008 adding additional functionality to various areas of the IDE. The source code is included and requires the VS SDK for VS 2008 to allow modification of functionality or as a reference to create additional custom PowerCommand extensions. Visit the VSX Developer Center at http://msdn.com/vsx for more information about extending Visual Studio.

The Releases page contains download files (MSI installation file, readme document, and source code project).


Below is a list of the included in PowerCommands for Visual Studio 2008 version 1.0. Refer to the Readme document which includes many additional screenshots.

Collapse Projects
This command collapses a project or projects in the Solution Explorer starting from the root selected node. Collapsing a project can increase the readability of the solution. This command can be executed from three different places: solution, solution folders and project nodes respectively.

Copy Class
This command copies a selected class entire content to the clipboard, renaming the class. This command is normally followed by a Paste Class command, which renames the class to avoid a compilation error. It can be executed from a single project item or a project item with dependent sub items.

Paste Class
This command pastes a class entire content from the clipboard, renaming the class to avoid a compilation error. This command is normally preceded by a Copy Class command. It can be executed from a project or folder node.

Copy References
This command copies a reference or set of references to the clipboard. It can be executed from the references node, a single reference node or set of reference nodes.

Paste References
This command pastes a reference or set of references from the clipboard. It can be executed from different places depending on the type of project. For CSharp projects it can be executed from the references node. For Visual Basic and Website projects it can be executed from the project node.

Copy As Project Reference
This command copies a project as a project reference to the clipboard. It can be executed from a project node.

Edit Project File
This command opens the MSBuild project file for a selected project inside Visual Studio. It combines the existing Unload Project and Edit Project commands.

Open Containing Folder
This command opens a Windows Explorer window pointing to the physical path of a selected item. It can be executed from a project item node

Open Command Prompt
This command opens a Visual Studio command prompt pointing to the physical path of a selected item. It can be executed from four different places: solution, project, folder and project item nodes respectively.

Unload Projects
This command unloads all projects in a solution. This can be useful in MSBuild scenarios when multiple projects are being edited. This command can be executed from the solution node.

Reload Projects
This command reloads all unloaded projects in a solution. It can be executed from the solution node.

Remove and Sort Usings
This command removes and sort using statements for all classes given a project. It is useful, for example, in removing or organizing the using statements generated by a wizard. This command can be executed from a solution node or a single project node.
Note: The Remove and Sort Usings feature is only available for C# projects since the C# editor implements this feature as a command in the C# editor (which this command calls for each .cs file in the project).

Extract Constant
This command creates a constant definition statement for a selected text. Extracting a constant effectively names a literal value, which can improve readability. This command can be executed from the code editor by right-clicking selected text.

Clear Recent File List
This command clears the Visual Studio recent file list. The Clear Recent File List command brings up a Clear File dialog which allows any or all recent files to be selected.

Clear Recent Project List
This command clears the Visual Studio recent project list. The Clear Recent Project List command brings up a Clear File dialog which allows any or all recent projects to be selected.

Transform Templates
This command executes a custom tool with associated text templates items. It can be executed from a DSL project node or a DSL folder node.

Close All
This command closes all documents. It can be executed from a document tab.

Use explicit casting instead of DataBinder.Eval

Posted in Visual Studio Tips and Tricks by priyangpatel on March 19, 2008

The DataBinder.Eval method uses .NET reflection to evaluate the arguments that are passed in and to return the results. Consider limiting the use of DataBinder.Eval during data binding operations in order to improve ASP.NET page performance.

Consider the following ItemTemplate element within a Repeater control using DataBinder.Eval:

<ItemTemplate>

<tr>

<td><%# DataBinder.Eval(Container.DataItem, “field1”) %><!–td>

<td><%# DataBinder.Eval(Container.DataItem, “field2”) %><!–td>

<!–<tr>

<!–<itemtemplate>

Using explicit casting offers better performance by avoiding the cost of .NET reflection. Cast the Container.DataItem as a DataRowView:

<ItemTemplate>

<tr>

<td><%# ((DataRowView)Container.DataItem)[“field1”] %><!–td>

<td><%# ((DataRowView)Container.DataItem)[“field2”] %><!–td>

<!–tr>

<!–ItemTemplate>

When returning DataReader from a function, specify CommandBehavior…

Posted in Visual Studio Tips and Tricks by priyangpatel on March 19, 2008

When you create an ADO.NET DataReader object, specify the CommandBehavior.CloseConnection enumeration in your call to ExecuteReader. This ensures that when you close the DataReader, the SQL connection is also closed. This is especially helpful when you return a DataReader from a function, and you do not have control over the calling code. If the caller forgets to close the connection but closes the reader, both are closed when the DataReader is created by using CommandBehavior.CloseConnection. This is shown in the following code fragment.

public SqlDataReader CustomerRead(int CustomerID)

{

//… create connection and command, open connection

return myCommand.ExecuteReader(CommandBehavior.CloseConnection);

}

 

//… client code

SqlDataReader myReader = CustomerRead(10248);

//… read some data

myReader.Close(); // reader and connection are closed

Next Page »