CONTENTS

INTRODUCTION

PART I: INTEGRATED DEVELOPMENT ENVIRONMENT

CHAPTER 1: A QUICK TOUR

Getting Started

The Visual Studio IDE

Summary

CHAPTER 2: THE SOLUTION EXPLORER, TOOLBOX, AND PROPERTIES

The Solution Explorer

The Toolbox

Properties

Summary

CHAPTER 3: OPTIONS AND CUSTOMIZATIONS

The Start Page

Window Layout

The Editor Space

Other Options

Importing and Exporting Settings

Summary

CHAPTER 4: THE VISUAL STUDIO WORKSPACE

The Code Editor

The Command Window

The Immediate Window

The Class View

The Error List

The Object Browser

The Code Definition Window

The Call Hierarchy Window

The Document Outline Tool Window

Reorganizing Tool Windows

Summary

CHAPTER 5: FIND AND REPLACE AND HELP

Quick Find/Replace

Find/Replace in Files

Find Symbol

Navigate To

Incremental Search

Accessing Help

Summary

PART II: GETTING STARTED

CHAPTER 6: SOLUTIONS, PROJECTS, AND ITEMS

Solution Structure

Solution File Format

Solution Properties

Project Types

Project Files Format

Project Properties

Web Application Project Properties

Web Site Projects

Summary

CHAPTER 7: INTELLISENSE AND BOOKMARKS

IntelliSense Explained

JavaScript IntelliSense

IntelliSense Options

Extended IntelliSense

Bookmarks and the Bookmark Window

Summary

CHAPTER 8: CODE SNIPPETS AND REFACTORING

Code Snippets Revealed

Accessing Refactoring Support

Refactoring Actions

Summary

CHAPTER 9: SERVER EXPLORER

Server Connections

Data Connections

SharePoint Connections

Summary

CHAPTER 10: MODELING WITH THE CLASS DESIGNER

Creating a Class Diagram

The Design Surface

The Toolbox

The Class Details

The Properties Window

Layout

Exporting Diagrams

Code Generation and Refactoring

Modeling Power Toys for Visual Studio

Summary

PART III: DIGGING DEEPER

CHAPTER 11: UNIT TESTING

Your First Test Case

Asserting the Facts

Initializing and Cleaning Up

Testing Context

Advanced Unit Testing

Testing Code Contracts

Managing Large Numbers of Tests

Summary

CHAPTER 12: DOCUMENTATION WITH XML COMMENTS

Inline Commenting

XML Comments

Using XML Comments

Generating Documentation with GhostDoc

Compiling Documentation with Sandcastle

Task List Comments

Summary

CHAPTER 13: CODE CONSISTENCY TOOLS

Source Control

Coding Standards

Summary

CHAPTER 14: CODE GENERATION WITH T4

Creating a T4 Template

T4 Building Blocks

How T4 Works

T4 Directives

Troubleshooting

Generating Code Assets

Preprocessed Text Templates

Tips and Tricks

Summary

CHAPTER 15: PROJECT AND ITEM TEMPLATES

Creating Templates

Extending Templates

Starter Kits

Online Templates

Summary

CHAPTER 16: LANGUAGE-SPECIFIC FEATURES

Hitting a Nail with the Right Hammer

A Tale of Two Languages

Visual Basic

C#

F#

Summary

PART IV: RICH CLIENT APPLICATIONS

CHAPTER 17: WINDOWS FORMS APPLICATIONS

Getting Started

The Windows Form

Form Design Preferences

Adding and Positioning Controls

Container Controls

Docking and Anchoring Controls

Summary

CHAPTER 18: WINDOWS PRESENTATION FOUNDATION (WPF)

What Is WPF?

Getting Started with WPF

The WPF Designer and XAML Editor

Styling Your Application

Windows Forms Interoperability

Debugging with the WPF Visualizer

Summary

CHAPTER 19: OFFICE BUSINESS APPLICATIONS

Choosing an Office Project Type

Creating a Document-Level Customization

Creating an Application Add-In

Debugging Office Applications

Deploying Office Applications

Summary

PART V: WEB APPLICATIONS

CHAPTER 20: ASP.NET WEB FORMS

Web Application vs. Web Site Projects

Creating Web Projects

Designing Web Forms

Web Controls

Master Pages

Rich Client-Side Development

ASP.NET Web Site Administration

Summary

CHAPTER 21: ASP.NET MVC

Model View Controller

Getting Started with ASP.NET MVC

Choosing a Model

Controllers and Action Methods

Rendering a UI with Views

Advanced MVC

Summary

CHAPTER 22: SILVERLIGHT

What is Silverlight?

Getting Started with Silverlight

Navigation Framework

Theming

Enabling Running Out of Browser

Summary

CHAPTER 23: DYNAMIC DATA

Creating a Dynamic Data Web Application

Customizing the Data Model

Customizing the Presentation

Enabling Dynamic Data for Existing Projects

Summary

CHAPTER 24: SHAREPOINT

Preparing the Development Environment

Exploring SharePoint 2010

Creating a SharePoint Project

Building Custom SharePoint Components

Working with Features

Packaging and Deployment

Summary

CHAPTER 25: WINDOWS AZURE

The Windows Azure Platform

SQL Azure

AppFabric

Summary

PART VI: DATA

CHAPTER 26: VISUAL DATABASE TOOLS

Database Windows in Visual Studio 2010

Editing Data

Previewing Data

Summary

CHAPTER 27: DATASETS AND DATABINDING

DataSets Overview

Binding Data

Working with Data Sources

Summary

CHAPTER 28: LANGUAGE INTEGRATED QUERIES (LINQ)

LINQ Providers

Old-School Queries

Query Pieces

Debugging and Execution

LINQ to XML

Querying XML

Schema Support

LINQ to SQL

LINQPad

Summary

CHAPTER 29: THE ADO.NET ENTITY FRAMEWORK

What Is the Entity Framework?

Getting Started

Creating an Entity Model

Querying the Entity Model

Advanced Functionality

Summary

CHAPTER 30: REPORTING

Getting Started with Reporting

Designing Reports

Rendering Reports

Deploying Reports

Summary

PART VII: APPLICATION SERVICES

CHAPTER 31: WINDOWS COMMUNICATION FOUNDATION (WCF)

What Is WCF?

Getting Started

Defining Contracts

Configuring WCF Service Endpoints

Hosting WCF Services

Consuming a WCF Service

Summary

CHAPTER 32: WINDOWS WORKFLOW FOUNDATION (WF)

What Is Windows Workflow Foundation?

Why Use Windows Workflow?

Workflow Concepts

Getting Started

The Workflow Foundation Designer

Creating a Workflow

Hosting the Workflow Designer

Summary

CHAPTER 33: CLIENT APPLICATION SERVICES

Client Services

Role Authorization

User Authentication

Settings

Login Form

Offline Support

Summary

CHAPTER 34: SYNCHRONIZATION SERVICES

Occasionally Connected Applications

Server Direct

Getting Started with Synchronization Services

Synchronization Services over N-Tiers

Background Synchronization

Client Changes

Summary

CHAPTER 35: WCF RIA SERVICES

Getting Started

Domain Services

Domain Operations

Consuming a Domain Service in Silverlight

Summary

PART VIII: CONFIGURATION AND RESOURCES

CHAPTER 36: CONFIGURATION FILES

.Config Files

Configuration Schema

Application Settings

User Settings

Referenced Projects with Settings

Summary

CHAPTER 37: CONNECTION STRINGS

Connection String Wizard

SQL Server Format

In-Code Construction

Encrypting Connection Strings

Summary

CHAPTER 38: RESOURCE FILES

What are Resources?

Resourcing Your Application

Satellite Resources

Accessing Specifics

Coding Resource Files

Custom Resources

Summary

PART IX: DEBUGGING

CHAPTER 39: USING THE DEBUGGING WINDOWS

The Code Window

The Breakpoints Window

The Output Window

The Immediate Window

The Watch Windows

The Code Execution Windows

The Memory Windows

IntelliTrace (Ultimate Edition Only)

The Parallel Debugging Windows

Exceptions

Summary

CHAPTER 40: DEBUGGING WITH BREAKPOINTS

Breakpoints

Tracepoints

Execution Control

Edit and Continue

Summary

CHAPTER 41: DATATIPS, DEBUG PROXIES, AND VISUALIZERS

DataTips

Debugger Attributes

Type Proxies

Visualizers

Advanced Techniques

Summary

CHAPTER 42: DEBUGGING WEB APPLICATIONS

Debugging Server-Side ASP.NET Code

Debugging Client-Side JavaScript

Debugging Silverlight

Tracing

Health Monitoring

Summary

CHAPTER 43: ADVANCED DEBUGGING TECHNIQUES

Start Actions

Debugging with Code

Debugging Running Applications

.NET Framework Source

Multi-Threaded and Parallelized Application Debugging

Debugging SQL Server Stored Procedures

Mixed-Mode Debugging

Post-Mortem Debugging

Summary

PART X: BUILD AND DEPLOYMENT

CHAPTER 44: UPGRADING WITH VISUAL STUDIO 2010

Upgrading from Visual Studio 2008

Upgrading to .NET Framework 4.0

Summary

CHAPTER 45: BUILD CUSTOMIZATION

General Build Options

Manual Dependencies

The Visual Basic Compile Page

C# Build Pages

MSBuild

Summary

CHAPTER 46: ASSEMBLY VERSIONING AND SIGNING

Assembly Naming

Version Consistency

Strongly Named Assemblies

The Global Assembly Cache

Signing an Assembly

Summary

CHAPTER 47: OBFUSCATION, APPLICATION MONITORING, AND MANAGEMENT

The MSIL Disassembler

Decompilers

Obfuscating Your Code

Application Monitoring and Management

Summary

CHAPTER 48: PACKAGING AND DEPLOYMENT

Windows Installers

ClickOnce

Summary

CHAPTER 49: WEB APPLICATION DEPLOYMENT

Web Site Deployment

Web Application Deployment

Web Project Installers

The Web Platform Installer

Summary

PART XI: CUSTOMIZING AND EXTENDING VISUAL STUDIO

CHAPTER 50: THE AUTOMATION MODEL

Visual Studio Extensibility Options

The Visual Studio Automation Model

Summary

CHAPTER 51: ADD-INS

Developing an Add-In

Deploying Add-ins

Summary

CHAPTER 52: MACROS

Understanding Macros

The Macro Explorer Tool Window

The Macros IDE

Creating a Macro

Running a Macro

Deploying Macros

Summary

CHAPTER 53: MANAGED EXTENSIBILITY FRAMEWORK (MEF)

Getting Started with MEF

The Visual Studio 2010 Editor

Extending the Editor

Summary

PART XII: VISUAL STUDIO ULTIMATE (AVAILABLE ONLINE)

CHAPTER 54: VISUAL STUDIO ULTIMATE FOR ARCHITECTS

Modeling Projects

Exploring Code

Summary

CHAPTER 55: VISUAL STUDIO ULTIMATE FOR DEVELOPERS

Code Metrics

Managed Code Analysis Tool

C/C++ Code Analysis Tool

Profiling Tools

Stand-Alone Profiler

IntelliTrace

Database Tools

Summary

CHAPTER 56: VISUAL STUDIO ULTIMATE FOR TESTERS

Automated Tests

Relating Code and Tests

Visual Studio Test Management

Test and Lab Manager

Summary

CHAPTER 57: TEAM FOUNDATION SERVER

Team Project

Process Templates

Work Item Tracking

Excel and Project Integration

Version Control

Team Foundation Build

Reporting and Business Intelligence

Team Portal

Team System Web Access

Administering TFS

TFS Automation and Process Customization

Summary

Index

Professional Visual Studio® 2010

Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com

Copyright © 2010 by Wiley Publishing, Inc., Indianapolis, Indiana

Published simultaneously in Canada

ISBN: 978-0-470-54865-3

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.

Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read.

For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.

Library of Congress Control Number: 2010922566

Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Visual Studio is a registered trademark of Microsoft Corporation in the United States and/or other countries. All other trademarks are the property of their respective owners. Wiley Publishing, Inc. is not associated with any product or vendor mentioned in this book.

To my beautiful Cynthia

—NICK RANDOLPH

 

To my wife Julie

—DAVID GARDNER

 

For Barbara, amore sempre

—MICHAEL MINUTILLO

 

For my parents, Michael and Narelle

—CHRIS ANDERSON

ABOUT THE AUTHORS

NICK RANDOLPH currently runs Built To Roam which focuses on building rich mobile applications. Previously, Nick was co-founder and Development Manager for nsquared solutions where he led a team of developers to build inspirational software using next wave technology. Prior to nsquared, Nick was the lead developer at Intilecta Corporation where he was integrally involved in designing and building their application framework.

After graduating with a combined Engineering (Information Technology)/Commerce degree, Nick went on to be nominated as a Microsoft MVP in recognition of his work with the Perth .NET user group and his focus on mobile devices. He is still an active contributor in the device application development space via his blog at http://community.softteq.com/blogs/nick/ and via the Professional Visual Studio web site, www.professionalvisualstudio.com/.

Nick has been invited to present at a variety of events including Tech Ed Australia, MEDC and Code camp. He has also authored articles for MSDN Magazine (ANZ edition), two books entitled Professional Visual Studio 2005 and Professional Visual Studio 2008, and helped judge the 2004, 2005, 2007 and 2008 world finals for the Imagine Cup.

DAVID GARDNER is a seasoned.NET developer and the Chief Software Architect at Intilecta Corporation. David has an ongoing passion to produce well-designed, high-quality software products that engage and delight users. Since the mid 90s, He has worked as a solutions architect, consultant, and developer and has lent his expertise to organizations in Australia, New Zealand, and Malaysia.

David is a regular speaker at the Perth .NET user group and has presented at events including Microsoft TechEd and the Microsoft Executive Summit. He holds a Bachelor of Science (Computer Science) and is a Microsoft Certified Systems Engineer. David was co-author of Professional Visual Studio 2008, and blogs about Visual Studio and .NET at www.professionalvisualstudio.com.

MICHAEL MINUTILLO is a .NET software engineer with a Bachelor of Science degree in Computer Science. A self-described “Indiscriminate Information Sponge,” he started writing .NET software in early 2000 to fund his university studies and has been an active member of the .NET community ever since.

Michael is a regular attendee at the Perth .NET Community of Practice where he has given presentations on the new features of C#, ASP.NET MVC and Test-Driven Philosophy. In 2009 Michael started the Perth ALT.NET User Group which meets monthly to discuss software engineering tools and practices in the .NET development space.

Michael maintains a technical blog at http://wolfbyte-net.blogspot.com and can be contacted at http://twitter.com/wolfbyte.

CHRIS ANDERSON has been a professional developer for over 10 years, specializing in building desktop, Web, and mobile business applications using Microsoft technologies for industries as wide ranging as accounting, property valuation, mining, the fresh produce industry, pet cremations, logistics, field services, sales, and construction. He holds a Bachelor of Engineering in Computer Systems with a Diploma in Engineering Practise. Chris is a co-owner of Peer Placements (a specialist recruitment firm for software developers) in addition to working as a consultant and author. Currently specializing in Silverlight (particularly in relation to building business applications in Silverlight), Chris has spoken on this topic at Code Camp Australia 2009, TechEd Australia 2009, Silverlight Code Camp Australia 2010, and numerous Sydney Silverlight Designer and Developer Network (SDDN) meetings for which he is a co-organizer. Chris maintains a blog at http://chrisa.wordpress.com and can be found on Twitter at http://twitter.com/christhecoder.

 

ABOUT THE TECHNICAL EDITOR

JOE BENNETT has been consulting as a developer and software solutions architect for more than 20 years and has been working with .NET exclusively since the beta for version 1.0. He is passionate about building well-architected, robust software for organizations of all sizes, and loves sharing his knowledge and experience with other developers.

Joe is the Chief Software Architect at Carolina Software Consultants, LLC and a past President of the Triangle .NET User Group located in the Triangle area of North Carolina. He frequently speaks at meetings and events and holds a Bachelor of Science degree in Computer Science from the University of Houston.

CREDITS

ACQUISITIONS EDITOR
Paul Reese

PROJECT EDITOR
Kelly Talbot

TECHNICAL EDITOR
Joe Bennett

PRODUCTION EDITOR
Eric Charbonneau

COPY EDITOR
Kim Cofer

EDITORIAL DIRECTOR
Robyn B. Siesky

EDITORIAL MANAGER
Mary Beth Wakefield

ASSOCIATE DIRECTOR OF MARKETING
David Mayhew

PRODUCTION MANAGER
Tim Tate

VICE PRESIDENT AND EXECUTIVE GROUP PUBLISHER
Richard Swadley

VICE PRESIDENT AND EXECUTIVE PUBLISHER
Barry Pruett

ASSOCIATE PUBLISHER
Jim Minatel

PROJECT COORDINATOR, COVER
Lynsey Stanford

PROOFREADERS
Scott Klemp and Beth Prouty, Word One

INDEXER
Johnna Vanhoose Dinse

COVER DESIGNER
Michael E. Trent

COVER IMAGE
© Eric Delmar/istockphoto

ACKNOWLEDGMENTS

THE PROCESS OF WRITING this book for Visual Studio 2010 has been frustrating at times; however, the journey of investigating new or forgotten features has reignited my passion for being a developer and working with one of the premiere development tools on the market. As with the previous two editions, this was a time-demanding exercise and I must again thank my partner, Cynthia, who consistently encouraged me to “get it done,” so that we can once again have a life.

I would especially like to thank everyone at Wrox who has helped me re-learn the art of technical writing—in particular, Kelly Talbot, whose attention to detail has resulted in consistency throughout the book despite there being four authors contributing to the process, and Paul Reese (whose ability to get us back on track was a life-saver), who made the whole process possible.

I have to pass on a big thank you to my co-authors, Dave, Mike and Chris, who agreed to work with me on this edition. I doubt that I really gave an accurate representation of exactly how much work would be involved, and I really appreciated having co-authors of such high caliber to bounce ideas off of and share the workload.

Lastly, I would like to thank all of my fellow Australian MVP developers and the Microsoft staff, who were always able to answer any questions along the way.

—NICK RANDOLPH

WRITING A BOOK IS WITHOUT A DOUBT among the most rewarding and challenging activities I’ve ever undertaken. I thought it would be easier the second time around, but alas I was quickly proven wrong. However, in the process I have amassed a wealth of knowledge that I never would have found the time to learn otherwise.

The production behind this book is significant, and I am especially thankful to the team at Wrox who worked tirelessly behind the scenes to bring it to fruition. Without Paul Reese and Kelly Talbot working as hard as they did to cajole the next chapter out of us, we never would have gotten this finished. It was a pleasure to be in such experienced hands, and I thank them for their patience and professionalism.

A huge thank you goes to my co-authors Nick Randolph, Michael Minutillo, and Chris Anderson, whose excellent contributions have improved this book significantly over the previous edition. I enjoyed collaborating on such a big project and the ongoing conversations about the latest cool feature that we’d just discovered.

My appreciation and thanks go to Gabriel Torok, Bill Leach, and Mike Moores from PreEmptive Solutions; Jonathan Carter from Microsoft; and SharePoint extraordinaire Jeremy Thake, whose feedback and suggestions greatly improved various chapters. Also thanks to my fellow coffee drinkers and .NET developers who (unintentionally) remind me how much I still have to learn about .NET development.

Special thanks to my parents, John and Wendy, who have always been there for me and who have always provided me with the encouragement and support I needed to achieve my goals. Special thanks also to my daughters Jasmin and Emily, who gave up countless cuddles and tickles so that Daddy could find the time to write this book. I promise I’ll do my best to catch up on the tickles that I owe you and pay them back with interest.

Most of all I would like to thank my extraordinarily supportive wife and best friend, Julie. She knew exactly what she was getting herself into when I agreed to write this book, and yet she still offered her full encouragement and support. Julie did way more than her fair share for our family when I needed to drop everything except work and writing, and I am truly grateful for her love and friendship.

—DAVID GARDNER

FIRST AND FOREMOST I’d like to thank my co-authors Nick and Dave for inviting me to join them on this adventure. That act of trust and faith has sustained me during several very early morning writing sessions. When I first appeared on the Perth .NET scene Nick and Dave welcomed me with loads of friendly advice and conversation. It’s an atmosphere that the community here retains to this day. A special thanks goes to Chris for racing me to the finish line. When one day we finally meet in person, I think I owe you a drink.

Like most first-time authors I had no real clue what I was getting myself into when I agreed to write this book. Thanks to the team at Wrox for patiently educating me. Special thanks goes to Kelly Talbot who continually worked to keep me on schedule and who coordinated the team that made my sections readable. Editing a technical book of this size has got to be an interesting challenge and ensuring consistency across four authors must make it particularly difficult.

Writing a book is a great way to teach you just how much you still have to learn. While researching material I was constantly surprised by the little corners of Visual Studio that I hadn’t previously been aware of, but there was always someone hanging out on twitter with a useful link or comment. There are too many of you to thank individually, so in true twitter style I’ll just say thanks and know that you are all listening.

Finally, I would particularly like to thank Barbara, the wonderful woman I am so lucky to be married to. When Nick and Dave first approached me about being involved in this book, I don’t think either of us realized the impact it would have on our lives. Barbara gave me the courage and the support to step up to the challenge and was ready to be banished from the house for whole weekends at a time, taking the kids on wonderful (and tiring) adventures so that I could get a chapter completed. To her and to my three beautiful children, Chiara, Caleb and Will, I promise I can come with you on the next adventure. And I won’t write any more books for a while. I promise.

—MICHAEL MINUTILLO

WHEN I WAS INVITED TO JOIN Nick, Dave, and Michael in writing this book, I had no idea what I was getting myself into. Writing is a gruelling and time-consuming process — far more than I could have ever imagined. Each chapter is almost like writing a thesis in itself, but on a strict time budget, only to move onto the next once it’s done. Knowing that thousands of people would be reading my chapters and relying on the information that they contain only added to the stress, but I am quite proud of what we’ve managed to produce, and hope that it gives you the skills and knowledge to become a Visual Studio power user. It’s been a big learning curve, and I came to realize how much I think and produce solely in code rather than in English. There’s a definite skill in effectively expressing concepts in the written form, and I have a newfound appreciation and respect for those who do it so well.

I’d like to thank Nick and Dave for inviting me to be a part of the team. I was very much honored to be asked and to actually be involved in this project. My thanks go to all three of my co-authors: Nick, Dave, and Michael. Despite being located at opposite sides of Australia I think we’ve worked remarkably well as a team, and I appreciate all your effort, feedback, and encouragement. My thanks also go to our editor Kelly Talbot, who kept us in check and valiantly (if not always successfully) attempted to keep us on schedule. While I have received help from a number of people at Microsoft, I must particularly thank Dustin Campbell and John Vulner who provided me with some valuable help and answers.

On a personal note, I would like to thank my parents Michael and Narelle, whose hard work, generosity, and love have been my inspiration.

—CHRIS ANDERSON

INTRODUCTION

 

 

Visual Studio 2010 is an enormous product no matter which way you look at it. Incorporating the latest advances in Microsoft’s premiere programming languages, Visual Basic and C#, along with a host of improvements and new features in the user interface, can be intimidating to both newcomers and experienced .NET developers.

Professional Visual Studio 2010 looks at every major aspect of this developer tool, showing you how to harness each feature and offering advice about how best to utilize the various components effectively. It shows you the building blocks that make up Visual Studio 2010, breaking the user interface down into manageable chunks for you to understand.

It then expands on each of these components with additional details about exactly how it works both in isolation and in conjunction with other parts of Visual Studio 2010 to make your development efforts even more efficient.

WHO THIS BOOK IS FOR

Professional Visual Studio 2010 is for all developers new to Visual Studio as well as those programmers who have some experience but want to learn about features they may have previously overlooked.

If you are familiar with the way previous versions of Visual Studio worked, you may want to skim over Part I, which deals with the basic constructs that make up the user interface, and move on to the remainder of the book where the new features found in Visual Studio 2010 are discussed in detail. While you may be familiar with most of Part I, it is worth reading this section in case there are features of Visual Studio 2010 that you haven’t seen or used before.

If you’re just starting out, you’ll greatly benefit from the first part, where basic concepts are explained and you’re introduced to the user interface and how to customize it to suit your own style.

WHAT THIS BOOK COVERS

Microsoft Visual Studio 2010 is arguably the most advanced integrated development environment (IDE) available for programmers today. It is based on a long history of programming languages and interfaces and has been influenced by many different iterations of the theme of development environments.

The next few pages introduce you to Microsoft Visual Studio 2010, how it came about, and what it can do for you as a developer. If you’re already familiar with what Visual Studio is and how it came to be, you may want to skip ahead to the next chapter and dive into the various aspects of the integrated development environment itself.

A Brief History of Visual Studio

Microsoft has worked long and hard on its development tools. Actually, its first software product was a version of BASIC in 1975. Back then, programming languages were mainly interpretive languages in which the computer would process the code to be performed line by line. In the past three decades, programming has seen many advances, one of the biggest by far being development environments aimed at helping developers be efficient at producing applications in their chosen language and platform.

In the 32-bit computing era, Microsoft started releasing comprehensive development tools, commonly called IDEs (integrated development environments), which contained not just a compiler but also a host of other features to supplement it, including a context-sensitive editor and rudimentary IntelliSense features that helped programmers determine what they could and couldn’t do in a given situation. Along with these features came intuitive visual user interface designers with drag-and-drop functionality and associated tool windows that gave developers access to a variety of properties for the various components on a given window or user control.

Initially, these IDEs were different for each language, with Visual Basic being the most advanced in terms of the graphical designer and ease of use, and Visual C++ having the most power and flexibility. Under the banner of Visual Studio 6, the latest versions of these languages were released in one large development suite along with other “Visual” tools such as FoxPro and InterDev. However, it was obvious that each language still had a distinct environment in which to work, and as a result, development solutions had to be in a specific language.

One Comprehensive Environment

When Microsoft first released Visual Studio .NET in 2002, it inherited many features and attributes of the various, disparate development tools the company had previously offered. Visual Basic 6, Visual InterDev, Visual C++, and other tools such as FoxPro all contributed to a development effort that the Microsoft development team mostly created on its own. The team had some input from external groups, but Visual Studio .NET 2002 and .NET 1.0 were primarily founded on Microsoft’s own principles and goals.

Visual Studio .NET 2003 was the next version released, and it provided mostly small enhancements and big fixes. Two years later, Visual Studio 2005 and the .NET Framework 2.0 were released. Subsequently Visual Studio 2008, coupled with the .NET Frameworks 3.0 and 3.5, was then released. These were both major releases with new foundation framework classes that went far beyond anything Microsoft had released previously. However, the most significant part of these releases was realized in the IDE where the various components continued to evolve in a cohesive way to provide you with an efficient tool set where everything was easily accessible.

The latest release, Visual Studio 2010 and .NET Framework 4.0, builds on this strong foundation. With the code shell being re-written to use Windows Presentation Foundation, many of the now out-dated designers have been given a new lease of life. In addition there are new designers to assist with building Silverlight applications and built-in support for building Office applications.

Visual Studio 2010 comes in several versions: Express, Professional, Premium and Ultimate. The majority of this book deals with the Professional Edition of Visual Studio 2010, but some parts utilize features found only in the Premium and Ultimate editions. If you haven’t used these editions before, read through Chapters 54 to 57 (available online) for an overview of the features they offer over and above the Professional Edition.

HOW THIS BOOK IS STRUCTURED

This book’s first section is dedicated to familiarizing you with the core aspects of Visual Studio 2010. Everything you need is contained in the first five chapters, from the IDE structure and layout to the various options and settings you can change to make the user interface synchronize with your own way of doing things.

From there, the remainder of the book is broken into 11 parts:

Though this breakdown of the Visual Studio feature set provides the most logical and easily understood set of topics, you may need to look for specific functions that will aid you in a particular activity. To address this need, references to appropriate chapters are provided whenever a feature is covered in more detail elsewhere in the book.

WHAT YOU NEED TO USE THIS BOOK

To use this book effectively, you’ll need only one additional item — Microsoft Visual Studio 2010 Professional Edition. With this software installed and the information found in this book, you’ll be able to get a handle on how to use Visual Studio 2010 effectively in a very short period of time.

This book assumes that you are familiar with the traditional programming model, and it uses both the C# and Visual Basic (VB) languages to illustrate features within Visual Studio 2010. In addition, it is assumed that you can understand the code listings without an explanation of basic programming concepts in either language. If you’re new to programming and want to learn Visual Basic, please take a look at Beginning Visual Basic 2010 by Thearon Willis and Bryan Newsome. Similarly, if you are after a great book on C#, track down Beginning Visual C# 2010, written collaboratively by a host of authors.

Some chapters discuss additional products and tools that work in conjunction with Visual Studio. The following are all available to download either on a trial basis or for free:

CONVENTIONS

To help you get the most from the text and keep track of what’s happening, we’ve used a number of conventions throughout the book.

Boxes with a warning icon like this one hold important, not-to-be forgotten information that is directly relevant to the surrounding text.

The pencil icon indicates notes, tips, hints, tricks, or asides to the current discussion.

As for styles in the text:

We use a monofont type with no highlighting for most code examples.
We use bold to emphasize code that's particularly important in the present context or to show changes from a previous codesnippet.

SOURCE CODE

As you work through the examples in this book, you may choose either to type in all the code manually, or to use the source code files that accompany the book. All the source code used in this book is available for download at http://www.wrox.com. When at the site, simply locate the book’s title (use the Search box or one of the title lists) and click the Download Code link on the book’s detail page to obtain all the source code for the book. Code that is included on the Web site is highlighted by the following icon:

Listings include the filename in the title. If it is just a code snippet, you’ll find the filename in a code note such as this:

code snippet filename

Because many books have similar titles, you may find it easiest to search by ISBN; this book’s ISBN is 978-0-470-54865-3.

Once you download the code, just decompress it with your favorite compression tool. Alternately, you can go to the main Wrox code download page at http://www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.

ERRATA

We make every effort to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error in one of our books, like a spelling mistake or faulty piece of code, we would be very grateful for your feedback. By sending in errata you may save another reader hours of frustration and at the same time you will be helping us provide even higher quality information.

To find the errata page for this book, go to http://www.wrox.com and locate the title using the Search box or one of the title lists. Then, on the book details page, click the Book Errata link. On this page you can view all errata that has been submitted for this book and posted by Wrox editors. A complete book list including links to each book’s errata is also available at www.wrox.com/misc-pages/booklist.shtml.

If you don’t spot “your” error on the Book Errata page, go to www.wrox.com/contact/techsupport.shtml and complete the form there to send us the error you have found. We’ll check the information and, if appropriate, post a message to the book’s errata page and fix the problem in subsequent editions of the book.

P2P.WROX.COM

For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a Web-based system for you to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums.

At http://p2p.wrox.com you will find a number of different forums that will help you not only as you read this book, but also as you develop your own applications. To join the forums, just follow these steps:

  1. Go to p2p.wrox.com and click the Register link.
  2. Read the terms of use and click Agree.
  3. Complete the required information to join as well as any optional information you wish to provide and click Submit.
  4. You will receive an e-mail with information describing how to verify your account and complete the joining process.

You can read messages in the forums without joining P2P but in order to post your own messages, you must join.

Once you join, you can post new messages and respond to messages other users post. You can read messages at any time on the Web. If you would like to have new messages from a particular forum e-mailed to you, click the Subscribe to this Forum icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works as well as many common questions specific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.

1

A Quick Tour

WHAT’S IN THIS CHAPTER?

Ever since we have been developing software, there has been a need for tools to help us write, compile, debug, and deploy our applications. Microsoft Visual Studio 2010 is the next iteration in the continual evolution of a best-of-breed integrated development environment (IDE).

This chapter introduces the Visual Studio 2010 user experience and shows you how to work with the various menus, toolbars, and windows. It serves as a quick tour of the IDE, and as such it doesn’t go into detail about what settings can be changed or how to go about customizing the layout, because these topics are explored in the following chapters.

GETTING STARTED

With each iteration of the Visual Studio product, the installation process has been incrementally improved, meaning that you can now get up and running with Visual Studio 2010 with minimal fuss. This section walks you through the installation process and getting started with the IDE.

Installing Visual Studio 2010

When you launch Visual Studio 2010 setup, you see the dialog in Figure 1-1 showing you the three product installation stages. As you would imagine, the first stage is to install the product itself. The other two stages are optional. You can either install the product documentation locally, or use the online (and typically more up-to-date) version. It is recommended that you do search for service releases because it ensures you are working with the most recent version of the product and associated tools.

FIGURE 1-1

As you progress through the setup process you are prompted to provide feedback to Microsoft (left image, Figure 1-2) and agree to the licensing terms for the product (right image, Figure 1-2).

FIGURE 1-2

The Visual Studio 2010 setup process has been optimized for two general categories of developers: those writing managed, or .NET, applications, and those writing native, or C++, applications (left image, Figure 1-3). The Customize button allows you to select components from the full component tree as shown in the right image of Figure 1-3.

FIGURE 1-3

Once you have selected the components you want to install, you see the updated progress dialog in the left image of Figure 1-4. Depending on which components you already have installed on your computer, you may be prompted to restart your computer midway through the installation process. When all the components have been installed, you see the setup summary dialog in the right image of Figure 1-4. You should review this to ensure that no errors were encountered during installation.

FIGURE 1-4

Running Visual Studio 2010

When you launch Visual Studio the Microsoft Visual Studio 2010 splash screen appears. Like a lot of splash screens, it provides information about the version of the product and to whom it has been licensed, as shown in Figure 1-5.

FIGURE 1-5

An interesting fact about the splash screen is that while a large portion of Visual Studio now uses WPF to display its content, the new splash screen in Visual Studio 2010 is still done in native code so that it displays as soon as possible after you start Visual Studio. A significant amount of time went into hand crafting the wave at the bottom of the splash screen, so make sure you marvel at it whenever you’re sitting there patiently waiting for Visual Studio to load.

The first time you run Visual Studio 2010, you see the splash screen only for a short period before you are prompted to select the default environment settings. It may seem unusual to ask those who haven’t used a product before how they imagine themselves using it. Because Microsoft has consolidated a number of languages and technologies into a single IDE, that IDE must account for the subtle (and sometimes not so subtle) differences in the way developers work.

If you take a moment to review the various options in this list, as shown in Figure 1-6, you’ll find that the environment settings that are affected include the position and visibility of various windows, menus, and toolbars, and even keyboard shortcuts. For example, if you select the General Development Settings option as your default preference, this screen describes the changes that will be applied. Chapter 3 covers how you can change your default environment settings at a later stage.

FIGURE 1-6

A tip for Visual Basic .NET developers coming from previous versions of Visual Studio is that they should not use the Visual Basic Development Settings option. This option has been configured for VB6 developers and will only infuriate Visual Basic .NET developers, because they will be used to different shortcut key mappings. We recommend that you use the general development settings, because these will use the standard keyboard mappings without being geared toward another development language.

THE VISUAL STUDIO IDE

Depending on which set of environment settings you select, when you click the Start Visual Studio button you will most likely see a dialog indicating that Visual Studio is configuring the development environment. When this process is complete, Visual Studio 2010 opens, ready for you to start work, as shown in Figure 1-7.

FIGURE 1-7

Regardless of the environment settings you selected, you see the Start Page in the center of the screen. However, the contents of the Start Page and the surrounding toolbars and tool windows can vary.

If you click the grey rounded rectangle with the text “Download the latest information for developers to the Start Page,” this pulls down news items from an RSS feed specified in the environment settings you specified. Each item is displayed in summary within the rectangle, allowing you to click through to the full article. You can customize this feed by changing the Start Page News Channel property on the Environment ⇒ Startup node of the Options dialog, accessible via the Options item on the Tools menu.

Before you launch into building your first application, it’s important to take a step back and look at the components that make up the Visual Studio 2010 IDE. Menus and toolbars are positioned along the top of the environment, and a selection of subwindows, or panes, appears on the left, right, and bottom of the main window area. In the center is the main editor space: whenever you open a code file, an XML document, a form, or some other file, it appears in this space for editing. With each file you open, a new tab is created so that you can toggle among opened files.

unpinned.