From: www.itworld.com
July 10, 2008 —
Windows Vista marked the release of the .NET Framework 3.0. This release included many great new features for the Windows developer. Among them was the initial release of Windows Presentation Foundation (WPF), Windows Communication Foundation (WCF), and Windows Workflow Foundation (WWF). However, Visual Studio remained unchanged. You could use these new features but they were not "built in" to the IDE. Instead, you had to use extensions to build applications on these .NET Framework elements and Visual Studio 2005.
Visual Studio 2008 represents a re-synch of the development tools and the .NET Framework. The .NET Framework evolves from 3.0 (released with Vista) to 3.5, an incremental release that ships with Visual Studio 2008. The IDE now natively supports WPF, WCF, and WWF out of the box. In addition, there are many other new bells and whistles including direct Office application support, CardSpace, LINQ, a large revision to ASP.NET, the CLR add-in framework, and more. In addition to Visual Studio, SQL Server will get an update in 2008.
NOTE
Although Visual Studio 2008 represents a major, milestone release, it is by no means the end for Visual Studio. On the heels of 2008 will be a large revision to Microsoft's developer collaboration tool, Visual Studio Team Systems and Team Foundation Server.
If you've been doing this very long, you've come to expect a new release like Visual Studio 2008 to come with new programming models, unfamiliar terms, fresh dialog boxes, and new ways to view code; it can be hard to find your footing on what seems to be unfamiliar ground. This chapter represents what to expect as a first encounter with Visual Studio 2008. We will first do a run-through of the tool to help you get your bearing. We'll then help you sort through the Visual Studio product line. Let this chapter serve as your map of what's great in 2008; it will get you moving in the right direction.
NOTE
Part I, "An Introduction to Visual Studio 2008," is broken into three chapters. This chapter covers what's new inside the tools and documents the product line. Chapter 2, "A Quick Tour of the IDE," is an introduction to getting the tool installed, running it, and creating that first project. It also serves to familiarize you with the basics of the IDE. In Chapter 3, ".NET Framework and Language Enhancements in 2008," we will cover the language and .NET Framework enhancements that are part of the 2008 release.
Visual Studio 2008 and the .NET Framework 3.5 introduce hundreds of new features to an already full-featured toolset. This latest version is about increasing developer productivity when writing applications targeted at the new version of the .NET Framework. This includes expanded project types, a reduction in mundane tasks, and ever-evolving aspects of team-oriented software engineering. This section and those that follow highlight these enhancements that promise to make your work life easier. Of course, we will go over each of these items in greater detail throughout the book; think of the content in this chapter as your "executive overview" for the hurried developer.
Many of us work in environments that include applications built on various versions of the .NET Framework. This becomes even more prevalent as more versions are released. For example, you may have an existing application in production built on .NET 2.0. You may be writing a new application on .NET 3.5. However, if your production application requires occasional maintenance, you do not want to have to keep two versions of Visual Studio on your machine.
Visual Studio 2008 supports the ability to target a specific version of the .NET Framework for an application. This means you can use a single tool to develop against many applications built on various .NET Framework flavors. Setting the .NET Framework version of an application will appropriately set the toolbox, project types, available references, and even IntelliSense inside the IDE to be in synch with the chosen .NET Framework version. Figure 1.1 shows creating a new application with Visual Studio 2008 and selecting the .NET Framework version (upper-right corner).
Notice the Add Reference dialog in Figure 1.2. It shows adding a reference to a Windows application that targets .NET Framework 2.0. In this instance, any component that is part of the 3.0 or 3.5 version of the .NET Framework is disabled (grayed out).
You can also decide to move your application to a different (hopefully newer) version of the .NET Framework. You can do so inside the project properties dialog (right-click your project file and select Properties). Figure 1.3 shows an example. Notice the Target Framework drop-down. You can change this and the IDE will then reset IntelliSense, reference, your toolbox, and more to the newly selected target framework.
Of course, you can use Visual Studio 2008 to open an existing application built on a prior version of the .NET Framework. When doing so, you have the option of upgrading or keeping it tied to the existing .NET Framework version. These features serve to help you upgrade to the advantages of 2008 and continue to work with applications built on an older version of the .NET Framework.
NOTE
The Framework setting is per project. Therefore, you can create a single solution that contains multiple projects and each can target a different version of the .NET Framework.
There have been a number of improvements to the overall management and access of the many Windows inside the IDE. Many user interface elements have a new look and new features.
Developers can now navigate open windows in the IDE without touching a mouse. This keeps your fingers on the keyboard and can lead to greater productivity. Visual Studio 2008 provides a couple of options here. The first is a simple Window switching hotkey. Suppose you have a number of code windows open in the IDE. To navigate forward (left to right) through them, you can use the key combination Ctrl+- (minus sign). This is for the standard development settings in the IDE; your settings may differ. To go backward (right to left), you use Ctrl+Shift+- (minus sign). This provides faster Window switching without your having to scroll with the mouse or search through your solution.
You can get similar results using a new visual aid called the IDE Navigator. This tool is similar to the Alt+Tab feature of Windows that allows for fast application switching. To access it, you use Ctrl+Tab (and Ctrl+Shift+Tab). You use this key combination to open the dialog and navigate open code Windows and active tool Windows. Figure 1.4 shows the result. Notice that active files are cycled through on the right.
TIP
To change the keyboard combinations assigned to the IDE navigator, select the menu option Tools, Options. Under the Environment node, select Keyboard. Here you can set keyboard shortcut keys. You will want to change the settings assigned to Window.NextDocumentWindowNav and Window.PreviousDocumentWindowNav.
Alternatively, you can access the IDE Navigator directly using Alt+F7. This brings up the tool with the active tool windows list selected. You can jump between the lists using the right- and left-arrow keys.
In prior versions, it was often difficult to get your code or tool window to dock correctly in the IDE. In 2008, docking windows is much improved. There are new icons and visualizations that make this process very simple. Figure 1.5 shows an example of docking the Server Explorer window on top of the Toolbox pane. You can see that there are options to move this window to the left of the toolbox, below it, and so on. Selecting each option shows a visual representation of the results before you release your mouse button.
Another welcome change to the IDE is the use of Windows standard dialog boxes for doing such tasks as opening a file, saving something, or printing code. In prior version of Visual Studio, the IDE had its own versions of these common tasks. However, this only made things confusing because most Windows users are accustomed to working using specific tools.
As an example, consider Figures 1.6 and 1.7. Figure 1.6 is the Open File dialog in Visual Studio 2005. This dialog was specific to Visual Studio. Figure 1.7 shows the same dialog in Visual Studio 2008. Notice that the dialog is the same dialog you would get in any other Windows-based application.
There is a new setting called Environment Font inside the Options dialog (Tools menu) under the Environment node, Fonts and Colors. This option allows you to set the font for the entire IDE to the selection of your choice. Figure 1.8 shows selecting this option from the list.
Changing this font changes your IDE. For example, suppose you set the Environment Font to Courier New, 8pt. This changes dialogs, menus, and more. Figure 1.9 shows the results of such a change.
Many of you have customized your IDE to fit your exact needs. These settings can be painful to have to re-create. Thankfully, Visual Studio 2008 supports settings migration. If, for example, you already have Visual Studio 2005 installed, Visual Studio 2008 will allow you to migrate these settings on startup.
Alternatively, if you are upgrading to a new computer or want to share your Visual Studio 2008 settings, you can do so using the Import and Export Settings tool. This option is available from the Tools menu in both Visual Studio 2005 and 2008. It is a wizard that allows you to import settings, export them to a file, or reset your settings to one of the IDE defaults. Figure 1.10 shows an example of exporting settings.
When you export or import settings, you can select those you want to apply. Figure 1.11 shows the second step in the export process. Notice you can pick and choose those items you want to export.
The final step when exporting is to save the file as a .vssettings file. This file can then be shared among users. It can also be used to migrate settings from one PC and one IDE version to another. With it, you can rerun the Import and Export Settings Wizard, choosing to import settings from a file.
Writing code is often a community thing. The developer community is broad and, for the most part, supportive of one another. Chances are, if you are having a problem, someone else has had the same issue. You can often reach out across the Internet and find solutions, components, sample code, articles, and the like that help to solve your issue. There is some kinship among developers that attracts them to posting sample code, newsgroup answers, and tips. Perhaps it is as simple as knowing that they may be the next in line to need an answer to a critical question, or maybe it's just the need to show off to one another. Either way, Visual Studio 2008 continues the community support that was built into 2005.
You can still author components targeted at the development community. In 2008, however, you can now indicate whether your components are targeted at both 2005 and 2008 or simply one or the other.
Another change to the community features is the simplification of the community menu items into a couple of menu items under the Help menu. The first menu item links directly to MSDN Forums and replaces Ask a Question and Check Question Status. This allows you to link to the forums and work directly with the features there. The second item is Report a Bug. This menu option replaces Send Feedback.
For more information on the community features of Visual Studio 2008 (and MSDN Forums), see Chapter 7, "The .NET Community: Consuming and Creating Shared Code."
The Class Designer was introduced in Visual Studio 2005. It provides a graphical means for writing and modifying classes. You can use it to define new classes and their relationships, add properties and methods to those classes, and modify elements within a property or method; it even allows for the refactoring of code. A change to a given method name within the Class Designer, for instance, will change the method's name as well as update all the method's callers to use the new name.
Visual Studio 2008 now provides Class Designer support for C++ applications. You can use it to visualize classes and their relationships. This includes seeing native C++ inheritance structures, enums, template classes, and more. There are, however, some limitations. If you are a C++ developer, you will want to review these inside of the production documentation.
The Class Designer is an integral part of Visual Studio Professional Edition and above. However, we cover it in detail inside the Visual Studio Team System part of the book, Chapter 26, "Development Edition."
.NET has quickly become pervasive throughout the entire Windows product world. It took only a few short years, but it is now fair to say that .NET is everywhere; Windows programming and .NET programming are now synonymous. Many of the user applications we interact with have some if not all of their base in .NET. This includes web applications, rich clients built on Windows, mobile applications, Office solutions, smart clients that work across the Web, and more. The good news is that the .NET developer is in high demand, and you can leverage your skills to target a wide audience.
Figure 1.12 shows the New Project dialog in Visual Studio 2008; it serves as an example of the myriad of user solutions that are possible with .NET.
Although Figure 1.12 shows many project templates, it does not represent a road map with respect to user applications. The .NET developer has many choices for creating the user experience using both Visual Studio and the new Expressions Studio (discussed later in the chapter). The following list is meant to provide an overview of the presentation technologies available to the .NET developer:
Each of these technologies is supported by Visual Studio 2008. With them, you have many options for creating user applications. This section highlights a number of development improvements in Visual Studio 2008 with respect to developing the user experience.
NOTE
There are many new client options in Visual Studio 2008. We highlight them all here. However, these and more are covered in greater detail throughout the rest of the book. Chapter 14, "Creating ASP.NET Applications," covers ASP.NET; Chapter 15, "Building Windows Forms Applications," is about standard Windows forms; Chapter 16, "Creating Richer, Smarter User Interfaces," focuses squarely on WPF; Chapter 17, "Creating Rich Browser Applications," discusses AJAX and XBAP applications; and Chapter 21, "Developing Office Business Applications," covers creating solutions based on Microsoft Office.
The vast majority of applications built these days involve some semblance of a web component -- be it a full-blown browser-based, web application; a smart client that works across the Web; a web service; or otherwise. In fact, the line between a traditional rich client and a web application is blurring. Technologies such as AJAX (Asynchronous JavaScript and XML), Web Services, Smart Clients, and XAML (Extensible Application Markup Language) have ensured this. You can now build rich user experiences as your needs dictate. Of course, Microsoft has remained suitably focused on expanding Visual Studio's capabilities with respect to web development.
Web developers want tools that help them through the common functions of building their application. Let's face it, the HTML, CSS, and XML standards can sometimes be a pain to follow by memory and by hand. Instead, we want tools that guide us. And of course, as soon as we want to work with code, we want to be able to access the entire related source and massage it as necessary. Visual Studio 2008 builds on recent (2005) enhancement. It's a step forward in adding productivity to the web development day. We highlight many of these advancements in the following sections.
NOTE
We will cover many of the items that follow (and more) in greater detail in Chapter 14.
AJAX represents the capability to leverage the ubiquitous support for JavaScript in web browsers to create a more interactive user experience. Client applications built to leverage AJAX still have a client-server paradigm. However, with AJAX the client can update portions of a given page without appearing to have posted back to the server (of course, it typically does). In addition, most AJAX-enabled applications put more processing on the client for things like toggling sections of a page, working with tabs, auto-completing data entry, popping up dialogs, and more. The result is a step forward in interactivity for a user.
AJAX is not a Microsoft-specific technology. It represents more of a programming model. However, Microsoft released the AJAX Extensions for Visual Studio targeting both the 2003 and 2005 versions. These controls allowed developers to more easily create AJAX experiences. These controls have been enhanced and are now incorporated into Visual Studio 2008 and the .NET Framework 3.5. Figure 1.13 shows the controls inside the Visual Studio Toolbox.
These controls allow you to create a page that can receive partial, asynchronous updates (using UpdatePanel) and show update progress (using UpdateProgress). They also allow you to create your own controls and features that implement AJAX without having to write the client-side JavaScript.
In addition to these controls, Visual Studio 2008 supports IntelliSense, code comment documentation, and client-side debugging for JavaScript. It also contains the Microsoft AJAX Library, which is a JavaScript common library that supports object-oriented development for JavaScript. For a detailed overview of these items, AJAX, and more, see Chapter 17.
Microsoft Silverlight
Microsoft's Silverlight is another exciting client technology for the Web. Silverlight allows for an even greater user experience delivered through the browser. You use it to create media-rich, highly interactive experiences. Silverlight requires a browser add-on (or plug-in). It works with Windows, Mac, and Linux in a wide variety of browsers. Silverlight does not ship with Visual Studio 2008; however, the Silverlight extensions for Visual Studio are available as a plug-in to the tool.
Visual Studio 2008 provides a rich set of tools and controls for the web developer. It still supports the standard controls for ASP.NET and HTML. This includes labels, text boxes, buttons, and the like. In addition, the validation, data, WebParts, and login controls are all still present. There are, of course, enhancements to many of these controls. However, here we focus on introducing the new controls for the ASP.NET developer.
There are three ASP.NET user interface controls that should be highlighted to the web developer: ListView, DataPager, and LinqDataSource. The first of these, ListView, is a control that simplifies the display of repeating data. The ListView control is driven based on user templates. In this way, you can easily configure how you want your UI to behave during operations such as view, edit, add, and delete. In addition, the ListView supports sorting, paging, and, of course, data binding. Figure 1.14 shows the Configure ListView screen. Here you can choose a default Runtime View layout, visual styles, and more.
The ListView control is template driven. You, of course, have complete access to the layout and control of these templates. In addition, the control can assist in setting up the appropriate template. Figure 1.15 shows the ListView Tasks. Notice that you can change the Current View shown in the WebForm designer to another template view.
Figure 1.16 shows the template view for the EditItemTemplate. Again, the template layout source is available for you to customize. In fact, in this example, we put the form labels and controls into a table for a cleaner look. Notice too that the record navigation is available from within these templates. This allows your users to cycle through sections of their data and make appropriate updates.
Another new control in 2008 that we'd like to highlight is the DataPager control. This control allows you to manage the paging of data and the UI associated with that paging. You can use this control by itself or embed it as part of another control you create. In fact, the ListView control mentioned previously already uses the DataPager control. You can associate other, data-bound controls to a DataPager by using the DataPager's PagedControlID property (the given control must implement the IPageableItemContainer interface).
You have full control over the customization, layout, and behavior of the DataPager. Figure 1.17 shows the DataPager Fields editor (accessed from the control's Tasks window). Notice that you can set appearance and behavior for all items associated with a given DataPager layout.
The final new ASP.NET control we will highlight here is the LinqDataSourceControl. LINQ (Language Integrated Query) is a new programming model introduced in Visual Studio 2008. It combines database query and .NET language. In this way, you can write strongly typed code (and not just simple strings) to query your data. This includes writing queries with full IntelliSense support that is based on your data. In addition, LINQ can work with data from various data sources including SQL Server, XML, and many more. For a richer overview of this new technology, check out Chapter 18, "Working with Databases."
The LinqDataSourceControl gives you the ability to bind controls using the LINQ technology in a familiar construct as other ASP.NET data sources. You can use the LinqDataSourceControl to gain access to database data, in-memory collections of data, data-source classes, and more. When you connect with these data sources, the LinqDataSourceControl allows you to write your data interaction using the power of LINQ. Your database query code for selecting, grouping, ordering, filtering, updating, inserting, and deleting will all be strongly typed and based on LINQ. In fact, the LinqDataSourceControl writes this code for you. Figure 1.18 shows an example of configuring a LinqDataSourceControl to connect and work with a LINQ data class.
Most web form developers switch between the Source and Design view of a web form many times during its development. The Source view allows you full access to editing the XHTML of the page. Design view lets you see the page develop and gives access to the many shortcuts attached to controls in the designer. Visual Studio 2008 makes this switching much easier. It provides a Split view. With it, you can see both the XHTML and the Designer. Figure 1.19 shows an example.
Split view tries to keep both the source and the design in synch. This works when you drag items from the toolbox to either the Source or the Design view panes. However, the Design view can get out of synch when you are doing a lot of edits to your source. In these cases, the Design view indicates that it is out of synch (see the middle of Figure 1.19). A click on the Designer and everything is back in synch. This new view can make developing your web forms more intuitive and more productive.
Styles and style sheets have been part of the web development world for years now. They help ensure a consistent look and feel that can be managed centrally. The CSS (cascading style sheet) specification also continues to evolve; it allow you to do more and more with the visual display of our applications. Of course, this introduces additional elements, attributes, and complexity. Thankfully, Visual Studio 2008 introduces better tools for creating and managing both inline styles (styles defined directly in your XHTML source) and style sheets (.css files).
One such tool is the Manage Styles pane available to the web form developer. Figure 1.20 shows the pane in action. From here you can attach a style sheet to a web form, create a new style, preview styles, and more. Notice the Options button and related menu. These options help you control which styles you want to see and how you want to see them.
Also revised for 2008 is the New Style/Modify Style dialog. Here you can create or modify a style based on the appropriate CSS spec (through 2.1). This dialog has been revamped to give you access to new features and make things a bit more intuitive. You can access this dialog from the Build Style button on the Style Sheet toolbar, from within a style sheet, or from within the Manage Styles pane using the New Style option. Figure 1.21 shows an example of the New Style dialog as accessed from the Manage Styles pane.
You can quickly apply styles to the elements on your page using the Apply Styles pane. Here you can see all the styles define on your form or the attached style sheet. Each style is shown with a visual representation for quick access. To apply the style, you simply select the form element and click the style. Figure 1.22 shows an example of this feature. Notice too that the ToolTip text for a style shows its CSS definition.
The final, new style management item we will cover here is the CSS Properties pane. Here you can quickly see the properties of a given style and manage them as you would the properties of a control. Figure 1.23 shows the use of this pane. Notice that you can work with styles defined within your web form. Each style is also grouped or available alphabetically. This can make things a bit easier for those who do not like to hunt through IntelliSense when defining styles.
Visual Studio 2005 introduced the capability to create master pages. These pages centralized the management of a site's design and navigation elements. In addition, master pages are supported by the designer, which allows for a richer design experience (and replaced the need for include files that were only seen in a browser). A developer is able to see the page in the context of the site's central design while in design mode.
One drawback, however, was that you could have only one level of master page. You could not nest master pages inside of each other and view the results in the designer. For example, a common scenario is to define a main master page to contain your site's frame, navigation, footer information, and the like. You might then create separate, sub-master pages for various content types. These sub-master pages would have their own, central design elements in addition to those defined by the main master page. Again, this scenario is not supported in 2005.
Thankfully, Visual Studio 2008 does support this scenario. With it, you can select an existing master page when creating a new master page. Figure 1.24 shows doing just that. Previously, during creation of a master page, this option was disabled.
With the new, nested master page, you can define master content inside the content placeholder defined by the main master page. You then add a new content placeholder inside your nested page. Pages based on this nested master page will put their content inside this area. Of course, you can go multiple levels deep with nested master pages. The designer will then show your various master pages during design. Figure 1.25 shows a simple example of an .aspx page created from a nested master page.
Rich clients are having a bit of a renaissance in 2008. The line between a web-based and Windows-like user experience continues to blur thanks to many UI advancements in terms of technology and tools. We have already discussed AJAX. Here we look at how 2008 allows you to create richer, smarter clients with Microsoft's new Windows Presentation Foundation (WPF).
WPF is both an addition to the .NET Framework and a set of tools with which developers can create richer solutions for the Web. The presentation code itself is based on XAML (Extensible Application Markup Language). The UI XAML is created using the Visual Studio WPF designer (or a similar tool called Expression Blend). The XAML is then run by the .NET CLR. Because it is processed on the client and not bound by HTML, it runs as a vector-based, hardware-accelerated user experience. The result is an extremely rich and interactive experience that supports both 2D and 3D graphics.
Visual Studio provides a familiar experience for creating WPF solutions. You first define a WPF project and add WPF forms to the project. When creating your solution, you select a project type based on whether the application will run as a browser add-in or as an installed desktop client. Figure 1.26 shows the WPF project templates. Selecting WPF Application will create a basic WPF application that is pushed to or installed on a client. It may have access to local resources on the client.
The WPF Browser Application, on the other hand, is meant to be deployed through a URL and run as a browser extension. The application, called an XBAP (XAML browser application), runs inside a sandbox. It does not have rights to the client machine and is cleaned up as part of the browser's cache. It does not require a download provided that the user has the .NET Framework 3.5 on their machine. It can work with the browser's cookies and is supported by both IE and Firefox.
Making the wrong choice here is not too problematic. You can move the WPF forms between application types. Note that the other two application types highlighted in Figure 1.26 are WPF User Controls and WPF Custom Control Library. Both are for creating reusable controls for WPF applications.
The next step in building your WPF form is to simply open it and drag and drop UI controls onto a design surface. One big difference for Windows developers, however, is that you now have control over the form layout code (or XAML). This is more akin to designing a web form with Visual Studio. Figure 1.27 shows the XAML designer in action.
Notice that the XAML controls are listed in the toolbox on the left. While they are similar to Windows and web controls, they are a new set of controls just for WPF. Also, notice how the designer has a split view between the design surface and the XAML. These stay in synch as you develop your code. Finally, the properties window shown on the left provides a similar experience when you're editing the many properties of a XAML control.
We cover the designer in greater detail in Chapter 16. Here we focus on the forms engine, the controls, event programming, debugging support, deployment, IntelliSense, configuration, and more inside of WPF.
When discussing WPF, it's important to note the work that went into the technology and tools to support a strong designer-developer workflow. It's understood that traditionally developers have been left to try to "design" the UI. It goes without saying that developers have not exactly shined as UI designers.
However, even in scenarios where designers were employed on projects, the design would often fall short or the implementation would be an arduous process. Designers had their own tools that did not talk with those of the developers. A design was often provided to the development team as a picture or some basic HTML. Developers were often left to try to realize the intricacies of the design while having to concern themselves with coding the solution. In the end, nobody was happy. The design was never exactly what was envisioned and developers would spend too much time trying to get the look right.
WPF tries to right this wrong. It keeps the UI markup (XAML) as totally separate from the implementation code (C# or VB). In addition, Microsoft has provided design tools that let designers create real user interfaces that can be leveraged by the development team. There are no more "lost in translation" issues. Instead, a designer can create or open a WPF UI element, edit it using the power of Expression Blend (they do not have to learn Visual Studio), and save it back to the solution or send it to a developer. The developer can then open the same item inside of Visual Studio and begin responding to key UI events with their code. This back-and-forth can continue as the UI builds up over time. Nobody's code gets stepped on; everyone focuses on their strength.
Figure 1.28 shows a sample of the Expression Blend tool. Notice that the same .xaml file (WFP form) is open here. Designers can use a tool with which they are more familiar to lay out the UI and apply visual techniques such as 3D and animation. Also notice that the C# project file is being used to maintain continuity between the solutions. After the designers are finished, their save goes right back to the development team. They can even test their UI in the context of the application by building and running the project.
Expression Blend
Microsoft's Expression Blend is a sister tool to Visual Studio 2008. It gives designers the ability to create rich WPF (XAML) forms, animations, and more -- all without code. You can also use it to build Silverlight applications.
Expression Blend is entirely built on WPF. It provides a great example of exactly what is possible with this technology.
Although the Expression suite of products is outside the scope of this book, you should be aware of these tools. We will provide an overview of them in the later section "The Visual Studio Product Line."
The many options for developing rich user experiences on Windows invariably leads to the question: "What is the right UI technology for my next Windows application?" Of course, the answer depends on your specific scenario. When making your decision, you should keep the intent of each technology in mind.
WPF is a Windows technology that requires the .NET Framework on the client. It can run in a browser sandbox or as a fully featured Windows application. You should leverage WPF when you need to create a rich user experience with high design aesthetics, want a low cost of installation and update, and require distributed connectivity.
Sliverlight, on the other hand, requires only a browser plug-in. The browser plug-in runs a mini version of the CLR on the client. In this way, you still can write your code in C# or VB and have access to bits of the .NET Framework. Silverlight is a very lightweight, cross-platform version of WPF. Its core strength is video, animation, and sound (multimedia). Think of Silverlight as an alternative to Adobe's Flash product.
Lastly, Windows forms still has a place in creating installed, business applications that connect with the operating system, leverage resources on the client, connect to databases, and more. They offer standard, workman-like user experiences for data entry, file manipulation, configuration, and related task-oriented solutions. They are easy to develop and do not typically involve much work from a design perspective.
Developers have been able to customize Office for a long time now; some of us still remember writing Excel macros on Windows 3.1 or automating Word with Word Basic. Visual Studio 2008 is another step forward for Office development. The tools are now are built into the IDE. With them, you can create Office-based projects and solutions that leverage Word, Excel, Project, Visio, PowerPoint, Outlook, SharePoint, and InfoPath.
There are project templates for all the Office products. In fact, you can create solutions for both Office 2003 and 2007. Figure 1.29 shows the New Project dialog for Office solutions. These are Visual Basic templates but the same exist for C#.
NOTE
Visual Studio Tools for Office (VSTO) is not part of Visual Studio Professional Edition. It is no longer a separate product. Visual Studio 2008 ships with the new VSTO 3.0. This should increase the awareness of these tools and their usage.
There are a few scenarios that would lead you to create an application based on Office. The most common is when you need to extend a line-of-business (LOB) application to provide functionality inside the common, information-worker productivity tools of Office. A LOB typically has a lot of rich data and some workflow.
For example, you may work with a financial, manufacturing, or payroll application. Each of these fills a specific need. However, users may need to work with the data that is housed inside the application and make key decisions that feed back into these systems. This work is often done through cut-and-paste and is often not captured by the systems. Users lose productivity switching back and forth between the Office tools and the LOB. This is where you should consider creating an Office Business Application (OBA) to help bridge this gap.
Notice the many templates in Figure 1.29. There are three separate templates for Excel 2007, for example. Each of these templates provides a specific purpose. Office application templates allow you to create solutions built on a single document, a document template, or as an add-in to the given Office application. The following list provides a brief overview of these three project subtypes:
Whichever template you choose, Visual Studio 2008 provides a rich, design-time experience for building your Office solution. As an example, Figure 1.30 shows the Visual Studio 2008 design experience building a solution for a Word 2007 Template. In this example, a user is creating a quote for training. The fields in the document pull from a LOB database that includes customer information, resource data, and common pricing.
VSTO 3.0 also provides design support for working with the Office 2007 Ribbon. In this way, your application can behave like the rest of Office. You can embed productivity features and aids on your own tab of the Office Ribbon. Figure 1.31 shows a simple example. The features here apply to the document template discussed previously. In this example, a developer provides specific features based on the document template and accessed by the user directly from Word's Ribbon.
SharePoint has become nearly as ubiquitous as Office. Companies are leveraging it for knowledge management, collaboration, and business process automation. Of course, this inevitably means customization and extension by developers. If you customized SharePoint using the existing tools for Visual Studio prior to 2008, you know that this presented a big challenge. The design-time support was not there, configuration was difficult, and debugging was very challenging.
Visual Studio 2008 presents a much richer toolset for SharePoint developers. With it, you can create SharePoint workflows (see the project templates back in Figure 1.29) and build WebParts based on ASP.NET. In addition, the debug experience has been reduced from approximately 15 to 5 steps in the IDE. SharePoint development is now a first-class consideration inside the IDE. This should streamline the process for extending SharePoint and help meet the business demand this collaboration product has generated.
This section highlighted many of the new features in VSTO 3.0 for Visual Studio 2008. There are many more advancements, however. These include access to open XML formats, the capability to add features to existing Outlook forms, custom task panes in Word and Excel, data binding, and improved deployment and security. We cover all of these and more in Chapter 21.
Visual Studio 2008 continues to extend the power to write applications that target mobile devices. This latest version allows you to build applications on a wide variety of technologies and devices. You can build solutions based on Windows Mobile 2003, Windows CE 5.0 and 6.0, and Windows Mobile 5.0 and 6.0 for both Smartphone and Pocket PC. In addition, you can target many devices and device types that leverage these operating systems and related versions of the .NET Compact Framework.
The IDE provides the forms designers, code editors, and debugging support for building mobile applications. You start with a Smart Device project. You can then select your Target Platform, the target version of the .NET Compact Framework (NetCF), and the project template type (forms application, class library, control, and so on). Figure 1.32 shows an example. Here the application is targeting Windows Mobile 5.0 and the latest version of NetCF.
Designing Windows Mobile forms is a familiar process. There is a set of device controls in the toolbox. You select a control and drop it on a Mobile form. The form looks and acts like the device you are targeting. Figure 1.33 is an example of the design experience. This example is a simple customer search form. Notice the menus at the bottom of the screen. You use these menus to allow the user to work with the form from the major keys on the phone (of course, a Smartphone has no stylus or mouse).
As you develop your application, you can deploy and test it against device emulators. This allows you to debug your application and see how it behaves on a simulated device. Visual Studio 2008 ships with the basic emulators for Smartphones and Pocket PC. However, there are more than 20 device emulators available for download. Figure 1.34 shows the application deployed and running on the basic Smartphone emulator. From here, you can interact with the application and debug your code.
A big addition for 2008 is the capability to write unit tests for mobile device applications. You can now create these tests using the standard unit test framework built into Visual Studio as of 2005. These unit tests behave the same way. In addition, they can integrate with Team System products (like Team Test) and publish test data to Team Foundation Server.
The Compact Framework 3.5 provides some welcome enhancements. These include support for LINQ data binding, Windows Communication Foundation, better compression, advancements in sound, better security management, and more.
Many business applications involve specific processes, or workflows, around documents, records, and related data. These business processes typically involve staged review and approval by business personnel; they might also require communication between various systems. A business process is also typically long-running -- meaning the process is not a simple, single execution but rather a multistep process that has to "wait" before moving to the next step.
Building these processes into business application was typically a lot of custom development work with little guidance, or it meant tying your application to third-party tools. Web services helped but developers lacked an easy way to build them with support for multiple protocols, different transports, strong security, and transactional support.
Visual Studio 2008 now provides in-the-box (and in the .NET Framework) support for building business processes as workflows and reliably integrating them with other applications, systems, and partners. This section takes a look at Windows Workflow (WF) for defining reusable business process and Windows Communication Foundation (WCF) for unlocking that business process across system boundaries.
NOTE
We will highlight .NET Framework and language enhancements (as opposed to IDE enhancements) to support communication and workflow in Chapter 3.
A workflow represents a set of actions (called activities) that are taken based on one another, business rules and conditions, and user actions. Workflows typically model business processes and often involve user interaction. Windows Workflow provides a framework, tools, and an engine for enabling workflows in your application. With it, you can create a workflow and know that it will run wherever the .NET Framework is installed.
You interact with workflows from within your application. This could be any type of application (Windows, ASP.NET, console, service, and so on). You typically submit data to the workflow and you might get a response, or you might use the workflow to kick off certain tasks or activities in your business process. The workflow can also persist itself during long-running transactions and then rehydrate on demand.
Two principal workflow types are built into Visual Studio 2008: sequential workflows and state-machine workflows. A sequential workflow follows a series of steps from top to bottom (as you design). Each step is gated based on the prior step and perhaps a set of conditions. A state-machine workflow, on the other hand, responds to different states (think status) being passed into the workflow. The states provide the gates between other states and may also trigger certain events.
You choose your workflow type at design type. There are both sequential and state-machine templates. Figure 1.35 shows an example of the workflow templates built into Visual Studio 2008. Notice also the SharePoint workflow templates. These provide the same workflows with extra hooks for SharePoint developers.
Building a workflow is a very visual process. The thought behind this is that workflows themselves are traditionally illustrated as a set of steps (boxes) and connections (arrows). You still have access to code, but the designer provides a strong visual tool for building both sequential and state-machine workflows. With it, you can indicate a start and end point, add activities to the diagram, and configure each activity in terms of its task.
Figure 1.36 shows a sequential workflow inside Visual Studio. On the left are the workflow activity shapes. You use these to visually represent your workflow. Each shape has a set of properties that require developer configuration. This simple workflow example allows for the approval of a sales quote. There is an if/then condition set to determine whether the sales quote requires approval. If so, the quote waits (or listens) for approval. The quote is then either approved or rejected by a user. If the user does not respond in a timely manner, a timeout message is sent. You can follow this workflow through the visual representation in the diagram.
The workflow toolset also includes a basic rules and conditions editor. This editor allows you to set and manage workflow rules. These rules are then output as XML to be configured at runtime should the need arise. Figure 1.37 shows an example of the rules editor. In this dialog, the sales quote value condition from the previous example is being set. This condition is then attached to the if/then activity in the diagram.
NOTE
See Chapter 20, "Embedding Workflow in Your Applications," for a more detailed discussion of the Windows Workflow tools.
Most organizations have multiple systems, each designed for a specific purpose. They may have a financial system, HR, order management, inventory, customer service, and more. These applications each house specific business processes. However, most organizations need to unlock these business processes from their application and reuse them as part of an integrated solution. This is where service-oriented solutions have helped. By exposing an application's business process as a service, multiple clients can take advantage of that process.
The promise of code reuse has been with us a long time. However, service-oriented code reuse became very popular with the advent of web services. The ubiquitous nature of HTTP and port 80 coupled with XML-based interfaces allowed for a new level of communication between application boundaries. Developers began wrapping key business functions as services and calling them from multiple clients.
Visual Studio 2008 and the .NET Framework 3.5 represent another step forward in this service-oriented paradigm. With these tools, you can create services based on Microsoft's Windows Communication Foundation. WCF is a framework which recognizes that developers need multiple layers of communication (not just the SOAP protocol carried over an HTTP transport), require strong security, often need to support transactions, and do not want to write all the plumbing code to do so.
You create WCF services as a code library, as a workflow, or as a web service application. Figure 1.38 shows the new project templates listed under the WCF project types. From here you can indicate that your web service contains a workflow (think business process) or simply create a service library that will call custom code you write.
You can also still create .asmx web services through the web project templates. This same template area also provides access to the new, WCF Service Application template. With it, you can create a WCF service that is configured similarly to a web service.
WCF is all about configuration. It frees you from having to write all the service plumbing code. Instead, you can focus on the functionality of your service. For example, you can add service endpoints to your service depending on which communication stack you intend to support (HTTP, TCP/IP, MSMQ, Named Pipes, and so on). Figure 1.39 shows the WCF configuration editor. Notice how the binding support for an endpoint is a configuration (and not coding) task.
NOTE
See Chapter 19, "Service-Oriented Applications," for a more detailed discussion of the tools for Windows Communication Foundation and web services.
Data is the domain of the business developer. It makes sense then that the number one tool and framework for business development continues to provide new and better ways of accessing and exposing that data. Data access is everywhere inside Visual Studio and the .NET Framework. Here we highlight some of the new things you will encounter in the 2008 version.
NOTE
Data access is covered in more detail in Chapter 18.
A typed dataset allows you to create a .NET class that is based on your database table semantics but works as a dataset behind the scenes. Typed datasets have been part of Visual Studio for a while now. You can auto-generate them based on table schemas and edit the code used to query, update, insert, and delete data.
Visual Studio 2008 provides additional design-time support for typed datasets. You can create a typed dataset file (.xsd) and use the Toolbox and Server Explorer to build the dataset. Figure 1.40 shows an example of this. Tables from the Server Explorer were added to the design surface to build the dataset.
In addition, the typed dataset in 2008 now supports hierarchical updates. This feature allows you to save data in multiple, related tables through the typed dataset. In Figure 1.40, this would mean you could edit both the employee details and the related territories and update as a single process.
Most business applications rely on data that is stored in relational databases. Databases have a well-known structure of tables, columns, and relationships. This structure makes for a nice storage and reporting mechanism. However, there is often a mismatch between the needs of an object-oriented, .NET developer and the database technology. The object developer thinks in terms of objects, properties, methods, relationships, encapsulation, and the like. A lot of time is spent converting data from a database into an object-oriented structure and back again. In addition, developers are asked to write code in Structured Query Language (SQL) and .NET.
LINQ, which we introduce in Chapter 3, is a technology that helps bridge this gap. It provides a means to work with database records as objects. It also allows you to write your queries using .NET (C# and VB). On top of LINQ is an object relational (O/R) designer for SQL Server called LINQ to SQL. With it, you can design and build .NET classes based on database schemas. In this way, you can quickly take database concepts and convert them to object-oriented ones.
You use a Visual Studio template to create a LINQ to SQL class. You can add such a class to any project type (web, Windows, class library, and so on). Figure 1.41 shows the Add New Item dialog with the LINQ to SQL Classes template selected.
You can then use the O/R Designer to build your LINQ class. You first use Server Explorer to open a connection to the database with which you are working. You can then drag and drop tables from the database onto the design surface. The designer understands (and enforces) the table relationships. It maps tables to classes and columns to properties.
Figure 1.42 shows an example of the designer. Here there is a customer class with an association link to the customer's orders. Notice also the methods listed on the right side of the diagram. These were created by dragging stored procedures from Server Explorer to the designer. A developer may now work with these classes and methods in a similar manner as they would with other .NET objects.
Many applications written these days require access to data both on- and offline. For example, you might need report data or customer service records when traveling or at a customer site. You cannot always rely on being connected. Developers have been dealing with this issue in various ways. The latest version of Visual Studio provides data synchronization services to provide a common, easy solution to this difficult problem.
Data synchronization allows you to synch and cache data between a central database and a user's client system. The cache is a version of SQL Server Compact Edition (CE). Microsoft is already taking advantage of these services in Vista, Office, and even their Zune software. You too can take advantage of these services in your applications.
Looking back at Figure 1.41, you will notice a template called Local Databa.... This template is actually called Local Database Cache. With it, you create a .sync file to configure how synchronization should happen between a local data store and a server. Opening the local database cache file in Visual Studio opens the Configure Data Synchronization dialog. Here you can set up tables that should be cached on a client, set up the server database, and configure the client database information. Figure 1.43 shows an example of this dialog.
The Cached Tables area of the Configure Data Synchronization dialog allows you to define which tables will be synchronized. Figure 1.44 shows an example of adding tables to this list. Here you configure how synchronization happens for each table. Synchronization services are discussed further in Chapter 18.
Like the 2005 version, Visual Studio 2008 comes in many flavors; each is baked for a different appetite. There is a recipe targeted at the hobbyist to the enterprise architect, the beta tester to the operations guy -- and, oh yeah, there are morsels for the developer too! Sorting through all the Visual Studio products and editions can be confusing. We hope the following aids you in your Visual Studio flavor selection.
Microsoft offers the Visual Studio Express Editions on a per-language basis (VB, C#, C++, Web, SQL). These editions are free, downloadable, low-barrier to entry versions targeted directly at the novice, hobbyist, student, or anyone else looking to write some code without breaking the bank. There is even an edition targeted at video game developers. Along with the editions are tutorials, videos, sites, fun projects, and more.
The Express Edition can be seen as Microsoft's answer to all the "freeware" tools available to today's developers. After all, if you are a college student looking to put up a buddy's website, you are more likely to look for the low-cost solution. Of course, five years down the road when you're making decisions for your company, Microsoft wants to be sure you've had a chance to work with its products. The Expression Edition fits this niche nicely.
These editions purposely do not have all the power of their professional patriarch (a Class Designer, unit testing, enterprise templates, XSLT support, source code control, 64-bit support, and so on). However, they do have full language support (like LINQ) and access to the .NET Framework items like WPF.
The Express Editions also have a more streamlined user experience that does not expose the full complexity (or power) of the professional editions. However, developers will be able to create client/server form-based applications, websites, and even web services using these tools.
NOTE
For more information regarding the Visual Studio Express Editions or to download one of these editions, you can visit Microsoft's site at the following URL: http://www.microsoft.com/express/default.aspx.
The Standard version of Visual Studio is the base-level entry point for professional developers. This edition is similar in nature to the Express Editions. However, it contains all the .NET languages in a single package. In addition, it gives developers an expanded feature set over the Express versions. These additional capabilities include the following:
Most corporate developers and consultants will find a home within one of the professional editions of Visual Studio. In fact, you may already have a version of Visual Studio depending on what license you bought and when. Visual Studio Professional gives you all the language support (including VB, C#, C++), everything in the Standard Edition, and, of course, the whole host of new enhancements we've discussed in this chapter.
The primary differences between standard and professional (besides the MSDN packaging) is a set of features that you do not get in the standard edition. The following features ship only with the professional version (and above):
Outside of these additional features, the Professional Edition is packaged as part of an MSDN subscription. Visual Studio Professional is packaged with various MSDN flavors. This change started with the 2005 version. You can now buy Visual Studio Professional as follows (listed from the fewest features/applications to the most):
NOTE
For more information regarding the professional editions of Visual Studio, you can visit Microsoft's site at the following URL: http://msdn2.microsoft.com/en-us/subscriptions/aa718657.aspx.
Team Systems is a set of integrated, software development life-cycle tools. Microsoft released the first versions of its Team Systems products in 2005. These included versions of Visual Studio targeted at various members of the software development life cycle. In the middle is a centralized management and reporting server called Team Foundation Server. By all accounts, these tools were a great success. Microsoft has built on this success with the release of Visual Studio Team Systems 2008.
The Visual Studio Team System editions are targeted to roles within the software development life cycle. These roles include developer, architect, tester, and database developer. In addition, there are client access licenses available for project managers and other interested parties. However, the aforementioned roles each represent versions of Team Systems that can be purchased.
It's important to note that each role-based version of Team Systems comes with Visual Studio 2008 Professional. It also comes with MSDN Premium (as defined previously). The Team System client tools also give you access to the central Team Foundation Server (purchased separately). What makes each of these products unique and significant, however, is what additional goodies they do and do not contain. The intent is a targeted set of tools to different roles on the project. The following list outlines the features that drive these products to their target users:
NOTE
We cover Team Systems features in great depth in Part VI of this book, "Visual Studio Team System."
Team Foundation Server (TFS) is at the center of Team Systems. While the client tools enable great functionality, the server allows you to assign work, report statistics, and track the overall health of your project. Project information is synchronized among architects, developers, testers, project managers, and operations.
The functionality behind Team Foundation Server revolves around project management and source control. Project management and tracking are accomplished through work items. A work item can be a task on the project, an issue or bug, a software requirement, a feature, or a test scenario. In general, a work item represents a generic unit of work on the project. Of course, work items are customizable and can have states, new fields, and business rules associated with them. Work items can also be driven by a methodology. Finally, work items play a central part in ensuring project team communication and reporting.
The source control features in Team Foundation Server include enterprise-class features such as change sets, shelving, automatic build rules, the capability to associate work items to changed source, parallel development, a source control policy engine, branching, checkpoints, and more.
Surrounding these project management and source control features are a build management engine, a reporting infrastructure, and a project portal. The build tools allow for both automatic, scheduled builds and on-demand builds. Builds are reported against, documented, automatically tested, and analyzed for code coverage and churn (as an example). The reporting engine and project portal combine to further enhance the view into the project by team members. Built on Windows SharePoint Services (WSS), it delivers the latest test and build reports, documentation, announcements, and quality analysis.
NOTE
You purchase TFS as you would any other Microsoft Server product (such as Microsoft SQL Server or Microsoft BizTalk Server). For more information on licensing TFS, see http://msdn2.microsoft.com/en-us/vsts2008/products/bb933758.aspx.
A sister product line to Visual Studio is the new Microsoft Expression tools. These will, undoubtedly, get a lot of attention in upcoming releases. The tools are targeted at designers' build applications on the Microsoft platform. They offer rich design experiences for building Web, Windows, and Silverlight applications. The tools are also built to enable workflow between designers and developers.
It is important that you are aware of these tools so that you know where you might use them and because they work with Visual Studio projects and project files and offer some similar capabilities (but in different ways). A high-level overview of these tools is listed here:
NOTE
For more information on the Expression products (not covered further in this book), see http://www.microsoft.com/expression/default.aspx.
A new release of Visual Studio means a lot to all the various development camps out there. Visual Studio touches developers who write code in C++, C#, Visual Basic, and many other languages. Literally millions of developers boot up and launch their favorite tool every day. They spend the vast majority of their working hours, days, weeks, and months architecting and building solutions with the tool. This chapter oriented you to some of the many new possibilities available with this latest version.
Sams