his installment of “The Baker’s Dozen” covers some of the major features in Visual Studio 2005.
Visual Studio 2005 offers language, data handling, and development environment enhancements that are sure to please many developers. Programmers who are currently using Visual Studio .NET 2003 will find many ways to write more efficient code and increase their overall productivity. In addition, programmers who are new to .NET will find the migration to Visual Studio 2005 a bit easier than the migration to the first version of .NET. While it’s not possible to talk about every new feature in Visual Studio 2005, this article will cover many of the primary changes and enhancements.
Beginning with the End in Mind
When I buy something (software, consumer electronics, etc.), it’s important for me to know the capabilities of the item I’m purchasing. I prefer to know up front what’s “under the hood” as opposed to finding out later. In our industry, developers and users feel the same way: they want to know the capabilities of a tool or product they’re about to use. So the objective of this article is to help developers new to Visual Studio 2005 become more aware and knowledgeable about the different areas where Microsoft has improved and enhanced .NET.
Baker’s Dozen Spotlight:
- Performance and functional enhancements to ADO.NET
- Language enhancements to C#
- Language enhancements to Visual Basic
- New Windows Forms capabilities
- New Web applications capabilities
- Click-once capabilities
- New features in the Visual Studio IDE to increase developer productivity
- SQL Server 2005 enhancements
- Crystal Reports.NET enhancements
- New features in the Visual Studio debugger
- Visual Studio 2005 Tools for Microsoft Office (managed code add-ins)
- An overview of Visual Studio Team System
- The new XML editor
With each tip, I’ll take a Sergeant Joe Friday…”the facts, just the facts” approach. Various sites, articles, and books (some of which I’ll mention) cover these areas in detail?it’s my objective to make you more generally aware of what’s under the hood in 2005, using a release notes approach. As much as possible, I’ll bold keywords and important topics, and you’re encouraged to research these further, either in the (greatly improved) on-line Help, and/or the suggested reading sources.
Reason 1: The Baker’s Dozen Spotlight: ADO.NET 2.0
Years ago I attended a Jethro Tull concert. Ian Anderson came out and started with Aqualung. Many of us were surprised that he started a concert with (arguably) their signature piece. But it only got better from there, so I’ll start with the area that I think shines the most in Visual Studio 2005: improvements in ADO.NET.
Performance: Microsoft has made two significant enhancements to ADO.NET that result in better performance. First, they rewrote the indexing engine for better performance. As a result, many operations execute more quickly, especially as the size of a dataset grows. Increases in performance will vary based on many application environment factors, but many applications should see increases by a factor of two or greater. One test published on MSDN that inserted a million rows into a data table took 30 minutes in Visual Studio .NET 2003 and 45 seconds in Visual Studio 2005! Lesser amounts of data will result in lower orders of magnitude; but in general, insert, update, delete, Fill, and Merge operations will execute more quickly in Visual Studio 2005.
Second, many developers know that passing and returning datasets across physical boundaries carries substantial overhead and incurs performance penalties. ADO.NET 2.0 supports true binary serialization in remoting environments by providing a new RemotingFormat property, which a developer can set to SerializationFormat.Binary.
Depending on the size of the dataset, the binary serialization may yield a result as much as six times smaller than XML serialization, resulting in faster transfer speeds and smaller required bandwidth resources. Note that this enhancement only works in remoting environments: because Web services (by definition) pass XML.
Datatable independence! In Visual Studio .NET 2003, several methods were only available for the dataset. One example is writing (and reading) XML data: a developer who wanted to write the contents of a data table to an XML file had to create a dataset, add the data table to the dataset, and use the dataset’s WriteXml method. ADO.NET 2.0 now provides the same method for the data table. The following is a full list of methods that are available at the data table level:
In addition, ADO.NET 2.0 allows a developer to serialize a data table in both remoting and Web service scenarios. The new RemotingFormat property described above also applies to the data table.
DataView.ToTable: ADO.NET 2.0 allows developers to create a new data table from any dataview. The ToTable method also contains an overload for the developer to create a subset list of columns in the new table.
Bulk Copy: ADO.NET 2.0 contains a new SqlBulkCopy class to perform bulk inserts of data from a .NET application to SQL Server. Any object that implements IDataReader can utilize the SqlBulkCopy capability.
Provider factories: In ADO.NET 1.1, supporting multiple data providers meant coding a CASE statement and IDbConnection. ADO.NET 2.0 has new provider factory classes to instantiate the desired provider type. At the end of this section, I’ll provide an excellent reference that covers this in detail.
Miscellaneous features: You can now fill a DataTable with a DataReader (and vice-versa). There’s a new SqlConnection class to obtain connection statistics, improved connection-pool handling, and multiple active result sets when using SQL Server 2005 and namespace-qualified tables.
I’m very pleased with the enhancements in ADO.NET 2.0. There are some enhancements that I hope Microsoft will consider for the next version. Even with the new independence of the data table, there are still capabilities that require a dataset. For instance, you can only establish a data relation between two data tables in the same dataset. Situations where master codes exist in multiple transaction tables require some additional coding when relations need to be established.
- Generic Coding with the ADO.NET 2.0 Base Classes and Factories by Bob Beauchemin MSDN). Bob Beauchemin has several excellent ADO.NET 2.0 articles online on MSDN.
- New Dataset Features in ADO.NET 2.0 by Jackie Goldstein (MSDN)
- Flex Your Data: Teach Old Data New Tricks with the Fully Loaded Advances in ADO.NET 2.0 by Julia Lerman (MSDN)
Reason 2: Language Enhancements in Visual C# 2.0
Visual C# 2.0 offers some impressive language enhancements. Here are a few of my favorites in no specific order of importance:
Generics: While C# is a strongly-typed language, there are times when a developer needs to create a generic object and later cast it to a specific type. A commonly-documented example is collections, where a developer can store references to any type of object and then perform a cast to retrieve the actual value of an index within the collection. Unfortunately, the developer surrenders the element of compile-time type safety, and this casting incurs a small performance penalty because of the boxing and unboxing that occurs.
New Namespace: Visual Studio 2005 provides a new namespace, Systems.Generic.Collections. This namespace allows a developer to create a generic collection and specify the permitted member types; consequently, the compiler will only permit the developer to add objects of the types previously declared. The developer no longer needs to perform cast operations to retrieve a value from a collection.
Anonymous Methods: These methods simplify the code required to implement event handlers. A developer can include code for an entire handler method in-line instead of instantiating a delegate and writing a method to which it points.
Partial Classes. You can use partial classes to define a class in more than one source file (using the new partial keyword). A common situation is a partial form class, where part of the class represents the Winform designer-generated code and the other part represents the developer’s code. Also, in a multi-developer environment, developers can work on different parts of the same class, and IntelliSense will display all members, properties, and methods from all parts. In a sense, Visual Studio merges all of the code from the different parts into one class. Of course, you cannot duplicate property and method names in any of the parts.
Partial classes open up new opportunities in several areas such as code generation projects. However, like any new capability, you should use partial classes judiciously. In some instances, a single class that is large enough to be logically divided among several developers might be a candidate for multiple classes. Additionally, a team should create meaningful naming conventions for each source file part.
In addition, Visual C# 2.0 supports generic iterators, static classes, and nullable types.
- Three Cool New Features in C# by Markus Egger (CoDe Magazine, January 2004)
- The C# Version 2.0 Specification from Microsoft
- Jesse Liberty has several excellent articles on www.ondotnet.com
- A Sneak Preview of Visual C# Whidbey (MSDN)
- Refactoring C# Code Using Visual Studio 2005 (MSDN)
Reason 3: ‘My’ Language Enhancements in Visual Basic 2005
Anyone with even basic knowledge of .NET knows that the .NET Framework has a large number of namespaces, classes, properties, etc. Many developers have commented that becoming proficient with the framework is the most difficult part of the learning curve?some even comment about the amount of time it takes just to learn and use the major namespaces.
In recognition of the learning curve, Microsoft has created a My hierarchy to improve access to commonly-used framework classes and assist new Visual Basic programmers in quickly performing common development tasks. The My hierarchy is divided into several categories. For example, one category is Computer for system information which is further broken down into subcategories like FileSystem and Printers.
Some of the C# enhancements described above (partial classes, generics) are also available in Visual Basic 2005. Additionally, Visual Basic 2005 now supports XML comments, a feature previously available to C# developers. This allows VB developers to insert comments that IntelliSense will use. Finally, Visual Basic 2005 supports a new in-line Using statement to instantiate an object and execute code, and then immediately release it (to avoid memory leaks).
- Language Enhancements in Visual Basic 2005 by Stan Schultes (MSDN)
- A Sneak Preview of Visual Basic 2005 by Ken Getz (MSDN)
- Oh My!! – A Look at the My Namespace in Visual Basic 2005 by Keith Franklin (CoDe Magazine, September 2004)
Reason 4: New Controls and Capabilities in Windows Forms
Microsoft has added new capabilities to Windows Forms that many Windows Forms developers will appreciate.
Masked Textbox: In Visual Studio .NET 2003, developers who wanted to use a data entry input mask either had to write their own or search for a third-party control. Visual Studio 2005 has a new MaskTextBox control. You can chose from several pre-defined masks such as Zip Code, SSN, Phone Number (with or without area code), Date, and Time. Alternatively, you can define custom input masks.
Visual Studio 2005 also provides new ToolStrip, StatusStrip, MenuStrip, and ContextMenuStrip controls (replacing the ToolBar, StatusBar, MainMenu, and ContextMenu controls). These provide a look and feel consistent with Microsoft Office System 2003.
Developers who want to create split windows can use the new SplitContainer control. Also, developers who instantiate data-bound controls on the fly (data-driven entry forms) and have to write complex code to cleanly align controls are in luck: the new FlowLayoutPanel and TableLayoutPanel controls contain a FlowDirection property to help control relative positioning of dynamically instantiated controls.
Many new developers found databinding in Visual Studio .NET 2003 to be daunting: Microsoft has made improvements to databinding through new capabilities such as the BindingSource and BindingNavigator components. Experienced developers who wrote custom code for binding solutions in Visual Studio .NET 2003 may elect to retain their investment, but newer developers will likely find Visual Studio 2005’s binding capabilities more to their liking. They can use binding with all data-bound controls, especially the new GridView control (which replaces the DataGrid control).
Finally, developers can implement Auto-complete functionality with the new textbox and combobox controls using the new AutoCompleteMode and AutoCompleteSource properties and, (optionally), the new AutoCompleteCustomSource collection.
- What’s New in the Visual Studio 2005 Toolbox for Windows Applications, by Dino Esposito (CoDe Magazine, January 2005)
- Brian Noyes presented sessions at the MSDN CodeCamp in Philadelphia on data binding in 2005. Go to www.phillydotnet.org/codecamp and search the Sessions page.
- Exploring New WinForm Controls in Visual Studio Whidbey by Michael Lane Thomas (CoDe Magazine, January 2004).
Reason 5: New Controls and Capabilities in Web Forms
I’ll freely confess that I’ve done very little production work with Web Forms. I’ve concentrated on Windows Forms. However, Microsoft has made significant enhancements to Web Forms and ASP.NET 2.0. In fact I’m devoting some serious study time towards them. Developers who previously dismissed Web Forms may want to take a look at the new capabilities in 2005. In the last few months, I’ve attended several excellent sessions on ASP.NET 2.0 that I’m using as training guides, so I’ll list the on-line versions of their presentations here
- The MSDN CodeCamp
- in Philadelphia had multiple sessions on ASP.NET 2.0. Go to www.phillydotnet.org/codecamp and search the Sessions page.
- Multiple articles in the March 2005 issue of CoDe Magazine
- The Web Applications chapter from Jesse Liberty’s new book, Visual C# 2005 – A Developer’s Notebook
- CoDe Magazine author and Microsoft MVP Miguel Castro has performed excellent sessions on ASP.NET 2.0. I’ve attended his sessions and I highly recommend them. His site is www.dotnetdude.com .
Reason 6: New Click-Once Capability
Visual Studio .NET 2003 featured No-Touch deployment. Visual Studio 2005 takes the concept one step further with Click-Once, a technology that allows developers to build a smart-client (Windows Form-based) application, publish the application in Visual Studio 2005 as a ClickOnce application, and deploy the application to users via a Web browser. When the developers update/upgrade the application on the server, they can do it in such a way that users will be automatically notified.
- ClickOnce: Deploy and Update Your Smart Client Projects Using a Central Server, by Brian Noyes (MSDN)
- Brian Noyes also presented a session at the MSDN CodeCamp in Philadelphia on ClickOnce. Go to www.phillydotnet.org/codecamp and search the Sessions page.
Reason 7: New Features in the Visual Studio 2005 IDE
I’m very pleased with the new IDE in Visual Studio 2005. Once developers start using it, they’ll immediately find themselves more comfortable with it. I find the new color-coded editor much easier and nicer to use than the editor in Visual Studio .NET 2003. I can create code snippets easily, and I find the new Help system much more powerful. From the IDE, I can easily access the MSDN-maintained Community Web services. I’ve been using different IDEs going back to the days of the Microsoft-Borland compiler wars (friendly wars), and can honestly say that the new IDE in Visual Studio 2005 is the best I’ve seen.
Reason 8: SQL Server 2005 Enhancements
While this article focuses on Visual Studio 2005, a significant percentage of .NET applications use SQL Server for the back-end: no doubt many of those applications will be running against SQL Server 2005 in the future.
From an application developer’s standpoint, there are two sets of enhancements to discuss: enhancements to the T-SQL language and the integration of the .NET CLR with SQL Server 2005.
PIVOT/UNPIVOT: Use these operators to rotate rows into columns, and vice-versa.
The APPLY operator allows a developer to specify a table-valued UDF in a FROM clause for each row in a table. The UDF can utilize columns from the source table as parameters. This can be helpful when creating a result set with calculated columns.
The TOP clause can now specify an expression as the number (variable) instead of a literal. You can also use TOP with INSERT, UPDATE, and DELETE commands to limit the number of rows affected.
CTEs (Common Table Expressions) allow developers to create recursive queries. They are similar to derived tables or views with the added capability of traversing recursive hierarchies in a single query.
SQL Server 2005 contains new data types: XML, VARCHAR (MAX), NVARCHAR (MAX), and VARBINARY (MAX). A developer can use the XML type to define parameters for stored procedures and UDFs. The types with MAX can optionally store up to 2 GB of data.
Also, SQL Server 2005 implements TRY?CATCH error handling. Finally, SQL Server 2005 can output a query plan as XML.
Integration with the CLR
This is a complex topic that I can hardly do justice to in a few paragraphs, so in the suggested reading below I’ll mention several good sources.
- Rod Paddock (Editor-in-Chief of CoDe Magazine) presented Custom Data Types and Aggregates at a conference. You’ll find his presentation on the download page of his Web site. He has written Creating User-Defined Data Types in Yukon (CoDe Magazine, January 2004).
- SQL Server 2005 T-SQL Enhancements by Jim Duffy (CoDe Magazine, March 2005)
- Bob Beauchemin, Niels Berglund, and Dan Sullivan have written an outstanding book, A First Look at SQL Server 2005 for Developers
Reason 9: A Very Welcome Enhancement in Crystal Reports for Visual Studio .NET
In the January/February 2005 issue of CoDe Magazine I presented 13 tips for Crystal Reports 10. A few people subsequently asked me why I used the external Crystal application for editing reports instead of the built-in Crystal Reports designer. While the external Crystal Reports application contains several design-time features, the answer was very simple: previewing! Crystal Reports in Visual Studio .NET 2003 lacked the ability to preview reports. Most of the reports I build are extensive enough that design-time previewing is essential?so I usually added the RPT as a strongly-typed report, but edit it outside of Visual Studio .NET 2003 using Crystal Reports 10.
Fortunately, the version of Crystal Reports that ships with Visual Studio 2005 (as of CTE 2.0, 10.2) provides a preview option. This should be a welcome enhancement if you build reporting applications. As a follow-up to my previous Crystal Reports article, I’ve presented a session at various conferences on building reporting solutions in a distributed environment where I provide an XML schema/data definition for the report at design time. To interactively test, I usually execute the stored procedure for the report, return the result set to a dataset, and then write out the dataset as an XML file.
The resulting XML file contains both the schema and sample data that I can use for both an overall data definition as well as for previewing.
Additionally, the Crystal Reports for Visual Studio .NET runtime preview window toolbar now has an Office 2003 look to it. To date, I haven’t discovered any other changes to Crystal Reports in Visual Studio 2005. If I discover any more, I’ll certainly update my site with additional information.
Reason 10: Better Debugger Visualizations
If you’ve written many database or data-driven applications in Visual Studio .NET 2003, very likely you’ve grown frustrated with debugging the contents of datasets. You had two options: either type the full expression in the Watch window (MyDataSet.MyTable.MyColumn, etc.), or write out the contents of the dataset to an XML file.
Fortunately, Visual Studio 2005 contains a new XML/DataSet Visualizer. During the debugging stage a developer can highlight a dataset in the code window, choose the Dataset Visualizer, and view the contents of the dataset in a simple grid.
The Visual Studio 2005 debugger contains a greatly improved interface for debugging complex objects, allowing a developer to view/debug complex data types in the appropriate viewer. Two thumbs up for the Visual Studio 2005 debugger!
- DataTips, Visualizers, and Viewers Make Debugging .NET Code a Breeze, by Morgan Skinner (MSDN)
Reason 11: Visual Studio 2005 Tools for Office
Visual Studio 2005 Tools for Office allows a developer to write Office 2003 applications using managed code add-ins. Using Visual Studio 2005 Tools for Office, a developer can host Word and Excel as designers inside Visual Studio 2005, and code directly against the document/spreadsheet objects. (This will be a topic of a future Baker’s Dozen article.)
- Best of Blogs: Visual Studio 2005 Tools for Office by Kevin Schuler (MSDN)
- In September, Microsoft Press will publish Programming with Microsoft Visual Studio 2005 Tools for the Microsoft Office System, Version 2.0
- Visual Studio 2005 Tools for Office (MSDN)
Reason 12: Visual Studio Team System
Visual Studio Team System is more than just a source-code control system; it is a comprehensive suite of tools for project managers, software architects, developers, and software testers. These tools aid in building visual architectures, code profiling and code coverage, change management, unit testing tools, load testing, and project management.
While Microsoft has stated they will continue to ship Visual SourceSafe as a solution for small teams, they have announced migration tools to upgrade a VSS database to Visual Studio 2005 Team System.
Reason 13: New XML Tools in Visual Studio 2005
Visual Studio 2005 contains an improved XML editor and many important enhancements to the XML classes in the System.Xml namespace. According to Microsoft, some of the enhancements (such as performance enhancements) were driven by messaging needs in Indigo.
- An Introduction to the XML Tools in Visual Studio 2005 by Neetu Rajpal (MSDN)
- What’s New in System.Xml for Visual Studio 2005 and the .NET Framework 2.0 Release by Mark Fussell (MSDN)
By the time this article appears, I’ll have a Windows Forms demo application available on my site. The main form is simply a picklist that launches subforms that demonstrate new functions in Visual Studio 2005 (a separate form to show databinding, a separate form to show the new GridView, etc.).
Also, for developers who are using the Common Ground Framework for .NET that I covered in the July/August 2005 issue of CoDe Magazine, I’m building a version of it for Visual Studio 2005. It will be available in November, when Microsoft releases 2005.
You can find the entire source code for this article on my Web site.
This is an on-going project, so there may be a few enhancements from time to time. Check the release notes Word document for details.