My Favorite New Features in Visual Studio 2010By Scott Mitchell
On Tuesday, April 13th, Microsoft released Visual Studio 2010 and the .NET Framework 4.0 (which includes ASP.NET 4.0). To get started with Visual Studio 2010 you can either download a trial version of one of the commercial editions or you can go grab the free Visual Web Developer 2010 Express Edition. The Visual Studio 2010 user experience is noticeably different than with previous versions. Some of the changes are cosmetic - gone is the decades-old red and orange color scheme, having been replaced with blues and purples - while others are more substantial. For instance, the Visual Studio 2010 shell was rewritten from the ground up to use Microsoft's Windows Presentation Foundation (WPF). In addition to an updated user experience, Visual Studio introduces an array of new features designed to improve developer productivity. There are new tools for searching for files, types, and class members; it's now easier than ever to use IntelliSense; the Toolbox can be searched using the keyboard; and you can use a single editor - Visual Studio 2010 - to work on .
This article explores some of the new features in Visual Studio 2010. It is not meant to be an exhaustive list, but rather highlights those features that I, as an ASP.NET developer, find most useful in my line of work. Read on to learn more!
I've often wondered how many man hours have been saved due to IntelliSense. IntelliSense, as every developer who has used Visual Studio knows, is that wonderful little drop-down list that lists matching type or member names while you type. IntelliSense lets you quickly see the available types and member names and saves countless keystrokes, as selecting a type or member from the list completes the type name or member name you were typing in.
Microsoft has made some changes to IntelliSense's behavior in Visual Studio 2010. In previous versions, the IntelliSense drop-down listed only those member names
that started with the characters you had typed in. For example, imagine that you needed to determine information about the currently requested URL. Knowing that
such information would be in the
Request object, but unsure of the property name, you enter
Request.Ur, presuming that the property would be named
Url or would start with the letters
Url. With Visual Studio 2008, entering
Request.Ur shows all members in the
object, but sorts them to show those that start with
Url first, such as
UrlReferrer (see the screen shot below).
The downside is that Visual Studio 2008's IntelliSense drop-down leaves you in the dark of the other URL-related
because this property does not start with the letters
Visual Studio 2010's IntelliSense works a bit differently. Instead of showing all members it shows only those that contain the letters you type in. As the screen shot
below shows, typing in
Request.Ur displays the three matching members:
What's more, Visual Studio 2010 supports Pascal casing IntelliSense searches. (All of the public types and members in the .NET Framework follow Pascal casing standards, which
capitalizes the first letter of the type or member along with each new successive word. Moreover, any acronyms, like HTTP or URL, have only the first letter capitalized and the
rest lower cased.) Pascal casing IntelliSense searches allow you to list types and members by entering just the capital letters in the type or member name. For example, typing
Request.QS shows the
QueryString member in the IntelliSense drop-down; entering
Server.MP shows the
MapPath member in the drop-down.
A Faster Add Reference Dialog Box
Each project in Visual Studio includes a list of assemblies which the project has access to. When creating a new project in Visual Studio, the most common references are automatically added, but it's not uncommon to need to add additional assemblies to a project when using less common parts of the .NET Framework, when dividing an application into separate projects, or when using third-party components. To add a new assembly to a project, go to the Solution Explorer, right-click on the project, and choose Add Reference. This launches the Add Reference dialog box, which has tabs like .NET, COM, Projects, and Browse. The .NET tab lists assemblies in the Global Assembly Cache (GAC), while the COM tab lists unmanaged COM objects found in the registry. The Projects tabs lists the other projects in your Visual Studio Solution, while the Browse tab is useful for adding an assembly by selecting it from the file system.
In Visual Studio 2008, the Add Reference dialog box opened on the .NET tab and used a single thread to scan the GAC. This would cause the Visual Studio user interface to "hang" while the GAC was being scanned and the .NET tab populated. Visual Studio 2010 improves this annoyance in two ways: first, the Add Reference dialog box opens to the Projects tab; second, going to the .NET tab spawns a new thread that scans the GAC in the background and populating the list asynchronously, meaning that if you accidentally opened the .NET tab you can close the Add Reference dialog box and get back to work without having to wait for the entire GAC to be scanned.
Finding Items in the Toolbox is Easier
With each new version of Visual Studio the number of items in the Toolbox seems to increase exponentially. Visual Studio has long used collapsible sections in the Toolbox to partition controls into various groups - Standard, Data, Validation, and so on. Visual Studio 2010 continues this tradition, but also allows developers to search the Toolbox using the keyboard. Simply click on the Toolbox to bring it into focus and then start typing.
As the screen shot to the right shows, the characters you type in are displayed in the bottom of Visual Studio's main window. (In the screen shot I have typed in the characters "tex".) Visual Studio highlights the first Toolbox item it finds that starts with the characters you've entered. If there are multiple matches, hit the Tab key to see the next result. Once the desired item is selected, hit Enter and the item will be added to the opened ASP.NET page's markup portion.
Visual Studio has long supported various search features, but all have felt a little clunky to me. In short, the search features in versions past limited you to searching for particular strings in files. You could search the current document, all open documents, or all files in a project or Solution, but at the end of the day the search was just searching the selected files for the string you entered.
Visual Studio still has these same search features built-in, but has added a new search window named Navigate To. (To bring up the Navigate To window, go to the Edit menu and choose the Navigate To menu item.) From the Navigate To menu you can type in the name of a class, a method, a property, an event, or a file name. The Navigate To window will search all of the types in your Solution and display any matches. When searching, the Navigate To window uses the same enhancements added to IntelliSense. Namely, it searches for types that contain the text you enter and also supports Pascal cased searches.
The screen shot below shows the Navigate To window when searching through an ASP.NET MVC project of mine. Note that my search term, "Controller", returns a variety of
results. It returns those classes that contain the word "Controller" in their name:
ProductsController. It contains the methods that have the word "Controller" in their name, in this case just one - the
BaseController class's constructor. And it returns any files whose name contains the text "Controller":
ProductsController.cs. Each different type of result displays a different icon, and
selecting a result displays its details. For instance, selecting the
BaseController constructor reports that the constructor is found in the PR.Web project
BaseController.cs file on line 25. Double-clicking a result opens the corresponding file on the appropriate line number.
Position Windows Anywhere!
Studies have found that having multiple monitors hooked up to a single computer can increase worker productivity up to 50% . Having gone to a multiple monitor setup several years ago, I cannot imagine going back to a single monitor. Previous versions of Visual Studio offered developers the ability to float certain windows and move them outside of the top-level window and to place them elsewhere (such as on another monitor). However, code and designer windows were locked into the top-level window.
The good news is that Visual Studio 2010's shell allows for any window to be floated and moved outside of the top-level window, including code and designer windows. This means you can have multiple code files lined up side-by-side across one or more monitors. You can move the debugging-related windows like Watch, Intermediate, and Call Stack off to a secondary monitor, and so on. Scott Guthrie has a great blog entry on how all windows can be moved outside of Visual Studio 2010's top-level window, and how this feature can improve usability on those systems with multiple monitors.
Traditionally, there has been a tight correspondence between the .NET Framework version you were working with and the version of Visual Studio you needed to use. For example, to develop ASP.NET 1.0 applications you needed to use Visual Studio .NET 2002. To work on ASP.NET 1.1 applications, you used Visual Studio .NET 2003. And for ASP.NET 2.0 applications you used Visual Studio 2005.
Visual Studio 2008 was the first version to offer multi-targeting, which allowed developers to develop against the .NET Framework 2.0, the .NET Framework 3.0, or the .NET Framework 3.5. Unfortunately, Visual Studio 2008 didn't actually implement true multi-targeting support. Rather, it took advantage of the fact that the .NET Framework versions 2.0, 3.0, and 3.5 all use the same core base class library. As Scott Guthrie describes in his blog post Multi-Targeting Support:
"[Visual Studio 2008's] multi-targeting experience worked – although it wasn't perfect. IntelliSense within VS 2008 always shows the types and members for the .NET 3.5 version of a framework library (even if you are targeting .NET 2.0). This means that you can sometimes inadvertently end up using a method that is only in ASP.NET 3.5 even when you are working on a ASP.NET 2.0 project."Visual Studio 2010 implements true multi-targeting support. When you create a new project in Visual Studio you can choose the target framework, which includes 2.0, 3.0, 3.5, and 4.0 (see the screen shot below). Based on the version you choose, Visual Studio shows the appropriate properties in the Properties window, the appropriate controls in the Toolbox, and the appropriate types and members in the IntelliSense drop-down list. (Note: Multi-targeting is not supported in the Express Edition.)
With this multi-targeting support you can use Visual Studio 2010 to work on ASP.NET 3.5 or ASP.NET 2.0 applications. One thing to keep in mind, however, is that the project files used in Visual Studio 2008 and Visual Studio 2010 differ, so you'll run into some friction if you have some developers working on an ASP.NET 3.5 site using Visual Studio 2008 and others working on the same site using Visual Studio 2010. For a workaround, check out Steve Dunn's blog, where he shares a command-line tool to switch project files between the Visual Studio 2008 and Visual Studio 2010 formats.
Visual Studio 2010 offers a vast assortment of improvements from its predecessors, from IntelliSense improvements to debugging enhancements. This article highlighted some of the new features ASP.NET developers might be most interested in.