Ask Kathleen

Tap into the Power of Visual Studio

Daily coding is a lot easier when you know how to use Visual Studio effectively. To optimize your experience with the latest Microsoft IDE, try these practical tips and shortcuts. (Part 3 of 3)

In the first and second parts of this three-part series on getting the most out of Visual Studio 2010, we looked at tips and tricks that can help developers get started with the new version of the IDE and do things like personalize the layout and improve navigation. In this installment, Kathleen explores tweaking the editor and working with search and IntelliSense.

Tweaks to the Editor
With previous versions of Visual Studio you could highlight a block by holding the Alt-Left mouse button and dragging. Now you have something useful to do with the block besides deleting it. Anything you type will simultaneously appear on all lines in the block.

If you have code with the wrong scope (shown here):   Simply type the replacement characters, in this case "pri":
 
[Click on image for larger view.]

Outlining is improved in Visual Studio 2010. If you position over the vertical line representing the outline, the associated outline block appears shaded. If you click the line, this block collapses. You can also hide code within a method by selecting it, right-clicking and selecting Outline/Hide Selection. This can make it easier to understand complex methods -- although breaking up complex methods remains a better strategy. Refactoring tools remain available in C# and through free third-party products for Visual Basic.

The splitter in the upper-right corner of the edit window works a little differently in Visual Studio 2010. The cursor no longer changes when you pass over it, but you can still pull it down to see multiple locations in a single file within the same window.

The left margin shows what files are changed. Yellow indicates changes that are not yet saved. Green marks lines that are saved, but don't match the originally opened file -- generally lines you can undo. A new orange color indicates lines that are the same as the original, but not yet saved. This generally happens when you undo back to the original, but an intermediate save means what's saved doesn't match what's displayed.

Search Shortcuts
Beyond Navigate To and Call Hierarchy, Visual Studio 2010 doesn't include new search features, but existing features are wildly underutilized. Beyond a simple search, you can Find in Files, Find Symbols, use F3 and Ctl-F3 for the next and previous, and use the quick find box in the toolbar. Find in Files lets you specify the directory to search and the file types. Find Symbols lets you limit your search by platform and create custom component sets for searching as well as supporting both prefix and substring searches. And you can use RegEx in many search dialogs.

There are two additional keyboard search tricks. If you select a set of characters in your code and hit Ctl-F3 or Ctl-Shift-F3, you'll navigate forward and back through any matches. If you press Ctl-I or Alt-I -- depending on your keyboard layout -- you'll enter incremental search mode and the cursor will change to an arrow and binoculars. In this mode, Visual Studio will refine your search as you type, moving to the next matching value. You can also hit F3 or Shift-F3 to navigate to the next or previous matches. Hitting these keys also ends incremental search mode and places your search text into the quick search box for easy reference or reuse.

Improved IntelliSense
IntelliSense received improvements in Visual Studio 2010. Visual Studio evaluates what you type against the Pascal interpretation of appropriate symbols, similar to the Pascal interpretation in the Navigate To dialog, narrowing IntelliSense options. This allows you to find things quickly where you remember only part of the symbol, generally the relevant portion, ignoring any preceding words like "Is" or "Allow." The abbreviations let you quickly enter the symbols you frequently use. IntelliSense is now filtered for the current target platform -- Microsoft .NET Framework 4 features won't appear in IntelliSense of a project targeting Microsoft .NET Framework 3.5.

Previous versions of IntelliSense were awkward in a test-driven development (TDD) environment where the symbols do not yet exist. IntelliSense could be quite pushy, requiring frequent presses on the Esc key. Visual Studio 2010 offers a second mode for IntelliSense mode called suggestion mode. This mode assumes you may or may not be entering an existing symbol. The top of the suggestion mode IntelliSense box displays what will be entered if you close IntelliSense. You can use arrow keys or the mouse to select an existing item, or enter your text as written without IntelliSense interference:


[Click on image for larger view.]

Visual Studio 2010 also provides TDD support through the Generate from Usage features. If you call to code that has not been created, you'll get a compiler error because the symbol is not found. The error correction dialog now includes Generate from Usage options. The specific options available are based on the context. If it looks like a method, property or field, appropriate options are displayed. If it looks like a type, available options are creating a new class or a new type. Creating a new class will create a new file in your current project with an empty class using the symbol name. Creating a new type displays a dialog with many options for how the new type is created, including the project where it's located.

There are numerous improvements to debugging across all versions, but I think debugging deserves a future column to itself.

Other Enhancements
Visual Studio 2010 also has many miscellaneous improvements and support for libraries. The WPF designer is improved, and there's a visual editor for the new Windows Workflow. XSLT gets a profiler and XSD gets a new designer. WPF and Silverlight get drag-and-drop data binding. ASP.NET gets many new features to support the vast improvements in development brought by jQuery and Model-View-Controller (MVC). The T4 code generator becomes a first-class citizen and a new style of T4 execution called preprocessed templates lets you generate code from apps outside Visual Studio, either with a standalone generator or your runtime application. Visual Studio 2010 embraces SharePoint development. Windows Azure Tools for Visual Studio 2010 support cloud development. There's better support for other languages, including F# in the box, and snippet support for HTML and JavaScript.

Whew! There are an amazing number of improvements, and I'm skipping the plethora of features resulting from the efforts in architecture, testing, database management and other areas that are reserved for the Ultimate version. You can find coverage of new features in Visual Studio 2010 Ultimate Edition in the July cover story, "Enabling ALM" (July 2010).

Upgrade Tips
Now for the caveats: If you move existing projects to Visual Studio 2010 from Visual Studio 2008 or 2005, your platform target is not updated. Visual Studio 2010 supports development targeting older framework libraries to aid in application deployment, but the project itself is altered to become a Visual Studio 2010 project and you won't be able to open it in Visual Studio 2008. On the surface the changes are just version number changes in the project and solution files. Beneath the surface, there's no guarantee that the structure of supporting files remains unchanged, so consider the move to Visual Studio 2010 a permanent one for your project, and keep backups in case you have a reason to revert. Changes to the workflow of data projects managed from Visual Studio (such as how you load scripts) are significant and may be confusing if you manage databases from Visual Studio.

Visual Studio 2010 is a full rewrite. While it's effectively a 1.0 product, overall performance and stability are adequate. But you're much more likely to experience quirky behavior (such as the Clipboard ring sometimes not working as expected) and occasional crashes than in Visual Studio 2008.

Pick up two or three tips a week from rereading this article, tip of the day sites, by having tips of the month at your local user group, or by exploring the menus and commands in the keyboard-mapping dialog. Consider buying Sara Ford's "Microsoft Visual Studio Tips" (Microsoft Press, 2008). Ford's book covers Visual Studio 2008, but almost all the tips also apply to Visual Studio 2010 -- and Ford's donating her author proceeds to the Save Waveland Scholarship Fund, for Hurricane Katrina survivors in Waveland, Miss. Wherever you get your tips, the ones that make your life easier will stick and you'll forget the ones that don't. Visual Studio is a tremendously powerful tool that you can't learn all at one time.

About the Author

Kathleen is a consultant, author, trainer and speaker. She’s been a Microsoft MVP for 10 years and is an active member of the INETA Speaker’s Bureau where she receives high marks for her talks. She wrote "Code Generation in Microsoft .NET" (Apress) and often speaks at industry conferences and local user groups around the U.S. Kathleen is the founder and principal of GenDotNet and continues to research code generation and metadata as well as leveraging new technologies springing forth in .NET 3.5. Her passion is helping programmers be smarter in how they develop and consume the range of new technologies, but at the end of the day, she’s a coder writing applications just like you. Reach her at [email protected].

comments powered by Disqus

Featured

Subscribe on YouTube