Lars Powers Mike Snell ® Microsoft Visual Studio 2008 UNLEASHED 800 East 96th Street, Indianapolis, Indiana 46240 USA Microsoft® Visual Studio 2008 Unleashed Copyright © 2008 by Pearson Education, Inc All rights reserved No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher No patent liability is assumed with respect to the use of the information contained herein Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions Nor is any liability assumed for damages resulting from the use of the information contained herein ISBN-13: 978-0-672-32972-2 ISBN-10: 0-672-32972-7 Library of Congress Cataloging-in-Publication Data Powers, Lars Microsoft Visual Studio 2008 unleashed / Lars Powers and Mike Snell p cm ISBN 978-0-672-32972-2 (pbk.) Microsoft Visual studio Microsoft NET Framework Application software— Development I Snell, Mike II Title TK5105.8885.M57P692 2008 006.7’882—dc22 2008017300 Printed in the United States of America First Printing June 2008 Editor-in-Chief Karen Gettman Executive Editor Neil Rowe Acquisitions Editor Brook Farling Development Editor Mark Renfrow Managing Editor Kristy Hart Project Editors Kristy Hart Anne Goebel Copy Editor Cheri Clark Senior Indexer Cheryl Lenser Proofreader Water Crest Publishing Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized Sams Publishing cannot attest to the accuracy of this information Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied The information provided is on an “as is” basis The authors and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book Bulk Sales Sams Publishing offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales For more information, please contact U.S Corporate and Government Sales 1-800-382-3419 corpsales@pearsontechgroup.com For sales outside of the U.S., please contact International Sales international@pearson.com Technical Editor Todd Meister Publishing Coordinator Cindy Teeters Cover Designer Gary Adair Composition Jake McFarland Contents at a Glance Introduction Part I An Introduction to Visual Studio 2008 A Quick Tour of Visual Studio 2008 A Quick Tour of the IDE 53 NET Framework and Language Enhancements in 2008 79 Part II An In-Depth Look at the IDE Solutions and Projects 105 Browsers and Explorers 135 Introducing the Editors and Designers 159 The NET Community: Consuming and Creating Shared Code 211 Part III Writing and Working with Code 251 Working with Visual Studio’s Productivity Aids Refactoring Code 285 10 Part IV Debugging Code 315 Extending Visual Studio 11 Introducing the Automation Object Model 365 12 Writing Macros 419 13 Writing Add-ins and Wizards 441 Part V Creating Enterprise Applications 14 Creating ASP.NET Applications 499 15 Building Windows Forms Applications 577 16 Creating Richer, Smarter User Interfaces 613 17 Creating Rich Browser Applications 653 18 Working with Databases 697 19 Service-Oriented Applications 749 20 Embedding Workflow in Your Applications 801 21 Developing Office Business Applications 853 Part VI Visual Studio Team System 22 Team Collaboration and Visual Studio Team System 881 23 Managing and Working with Team Projects 895 24 Source Control 921 25 Work Item Tracking 949 26 Development Edition 995 27 Architecture Edition 1047 28 Test Edition 1079 29 Database Edition 30 Team Foundation Build 1153 1115 Index 1173 Table of Contents Introduction Part I 1 An Introduction to Visual Studio 2008 A Quick Tour of Visual Studio 2008 Some Welcome Enhancements to the IDE Use a Single Tool for Many Jobs Cleaner Windows 10 Keep Your Settings 13 Share (and Consume) Code with the Community 16 Expanded Class Designer Support 16 Develop User Applications 17 Enhance the Web Developer’s Productivity 18 Smarter Clients 27 Office-Based Solutions 32 Target Mobile Devices 36 Write Connected, Service-Oriented Solutions 38 Develop an Application/Business Process 38 Create and Consume Services 41 Work with Data 42 Design Your Data 43 Map Objects to Relational Data 43 Build Occasionally Connected Applications 46 The Visual Studio Product Line 47 Express Editions 47 Standard Edition 48 Professional Edition 49 Team Systems 50 The Expression Tools 51 Summary 52 A Quick Tour of the IDE 53 Installing Visual Studio 53 Choosing a Language 53 Configuring Your Development Environment 54 vi Microsoft Visual Studio 2008 Unleashed The Start Page 57 Startup Options 57 Your First Project 59 The Menu Bar 59 The Many Toolbars 64 The Standard Toolbar 64 Customizing Toolbars 65 The Toolbox 67 The Visual Designers 69 The Text Editors 70 The Code Editors 70 Editor Customizations 72 The Solution Explorer 73 The Properties Window 74 Managing the Many Windows of the IDE 75 Pinning 75 Docking 76 Summary 78 NET Framework and Language Enhancements in 2008 79 An Overview of the Visual Studio 2008 IDE Enhancements by NET Language 80 VB IDE Enhancements 80 C# IDE Enhancements 81 NET Language Additions in 2008 82 Infer a Variable’s Data Type Based on Assignment 83 Create an Object and Set Its Properties with a Single Line of Code 85 Add Methods to Existing Classes 87 Create an Instance of a Nonexistent Class 88 Write Simple, Unnamed Functions Within Your Code 89 Add Business Logic to Generated Code 91 Access and Query Data Using the NET Languages 94 Split an Assembly Across Multiple Files 95 Work with XML Directly Within Your Code 96 Remove Unused Arguments from Event Handlers (VB Only) 97 Create an Automatically Implemented Property (C# Only) 97 NET Framework 3.5 Enhancements 98 Summary 101 Contents Part II vii An In-Depth Look at the IDE Solutions and Projects 105 Understanding Solutions 105 Creating a Solution 106 Working with Solutions 111 Getting Comfortable with Projects 117 Creating a Project 117 Working with Project Definition Files 121 Working with Projects 127 Summary 132 Browsers and Explorers 135 Solution Explorer 135 Visual Cues and Icons 136 Managing Solutions 141 Managing Projects 141 Class View 142 Toolbar 142 Search Bar 144 Objects Pane 144 Members Pane 146 Server Explorer 147 Data Connections 148 Server Components 149 Object Browser 152 Changing the Scope 153 Browsing Objects 153 Document Outline 155 Editing Elements 157 Summary 157 Introducing the Editors and Designers 159 The Basics 159 The Text Editor 160 Visual Studio Designers 162 Coding with the Code Editor 163 Opening an Editor 163 Writing Code in the Code Editor 164 Anatomy of the Code Editor Window 165 Code Navigation Tools 168 Searching Documents 170 viii Microsoft Visual Studio 2008 Unleashed Debugging in the Text Editor 178 Printing Code 181 Using the Code Definition Window 183 Creating and Editing XML Documents and Schema 183 Inferring Schema 185 Editing XSLT Style Sheets 185 Working with Cascading Style Sheets 186 Adding Style Rules 187 Defining Style Sheet Attributes 187 Developing Windows Client Applications 187 Creating a Windows Forms Project 188 Creating a Windows Presentation Foundation Project 197 Developing Web Forms 200 Designing a Web Form Application 200 Authoring Components and Controls 206 Creating a New Component or Control 206 Further Notes on Writing Component Code 207 Summary 209 The NET Community: Consuming and Creating Shared Code 211 The Community Features of Visual Studio 211 The Visual Studio Start Page 212 The Help Menu 217 Discovering and Consuming Shared Content 228 Examining Shared Content Types 228 Finding the Right Content 229 Installing and Storing Shared Content 229 Participating in the Community 231 Creating Shared Items (Project and Item Templates) 232 Creating Project Templates 232 Creating Item Templates 238 Packaging Your Creation 239 Publishing Your Creation 247 Summary 248 Part III Writing and Working with Code Working with Visual Studio’s Productivity Aids 251 Basic Aids in the Text Editor 253 Change Tracking 253 Coding Problem Indicators 254 Active Hyperlinking 255 Contents ix Syntax Coloring 255 Outlining and Navigation 256 Code Outlining 257 HTML Navigation 259 Smart Tags and Smart Tasks 260 HTML Designer 261 Windows Forms Designer 261 Code Editor 262 IntelliSense 263 Complete Word 264 Quick Info 265 List Members 265 Parameter Info 267 Organize Usings 268 Code Snippets and Template Code 268 Brace Matching 277 Customizing IntelliSense 279 The Task List 280 Comment Tasks 281 Shortcut Tasks 283 User Tasks 283 Summary 283 Refactoring Code 285 Visual Studio Refactoring Basics 286 Invoking the Refactoring Tools 287 Previewing Changes 291 Rename 292 Accessing the Rename Operation 292 Working with the Rename Dialog Box 294 Extract Method 295 Accessing the Extract Method Refactor 296 Extracting Methods 296 Generate Method Stub 303 Extract Interface 303 Accessing the Extract Interface Refactor 304 Extracting Interfaces 305 Refactor Parameters 307 Remove Parameters 307 Promote Local to Parameter 309 Reorder Parameters 311 ...Lars Powers Mike Snell ® Microsoft Visual Studio 2008 UNLEASHED 800 East 96th Street, Indianapolis, Indiana 46240 USA Microsoft Visual Studio 2008 Unleashed Copyright © 2008 by Pearson Education,... Edition 888 xvi Microsoft Visual Studio 2008 Unleashed Visual Studio Team System Test Edition 890 Visual Studio Team System Database Edition... herein ISBN- 13: 978-0-672-32972-2 ISBN- 10: 0-672-32972-7 Library of Congress Cataloging-in-Publication Data Powers, Lars Microsoft Visual Studio 2008 unleashed / Lars Powers and Mike Snell p cm ISBN