Moving to Microsoft Visual Studio 2010 ebook.pdf -...

This preview shows page 1 out of 336 pages.

Unformatted text preview: PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2011 by Microsoft Corporation All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. Library of Congress Control Number: 2010934433 Printed and bound in the United States of America. Microsoft Press books are available through booksellers and distributors worldwide. For further infor­mation about international editions, contact your local Microsoft Corporation office or contact Microsoft Press International directly at fax (425) 936-7329. Visit our Web site at . Send comments to [email protected] Microsoft and the trademarks listed at Trademarks/EN-US.aspx are trademarks of the Microsoft group of companies. All other marks are property of their respective owners. The example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred. This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Acquisitions and Developmental Editor: Devon Musgrave Project Editors: Roger LeBlanc and John Pierce Editorial Production: MPS Limited, a Macmillan Company Technical Reviewer: Todd Meister; Technical Review Services provided by Content Master, a member of CM Group, Ltd. Cover: Tom Draper Design Body Part No. X17-13257 Table of Contents Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii Part I Moving from Microsoft Visual Studio 2003 to Visual Studio 2010 1 From 2003 to 2010: Business Logic and Data . . . . . . . . . . . . . . . . . 3 Application Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Plan My Night Data in Microsoft Visual Studio 2003 . . . . . . . . . . . . . . . . . . . . 5 Data with the Entity Framework in Visual Studio 2010 . . . . . . . . . . . . . . . . . . . 6 EF: Importing an Existing Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 EF: Model First . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 POCO Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Putting It All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Getting Data from the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Getting Data from the Bing Maps Web Services . . . . . . . . . . . . . . . . . . 32 Parallel Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 AppFabric Caching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 2 From 2003 to 2010: Designing the Look and Feel . . . . . . . . . . . . 39 Introducing the PlanMyNight.Web Project . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Running the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Creating the Account Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Implementing the Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Creating the Account View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Using the Designer View to Create a Web Form . . . . . . . . . . . . . . . . . . . . . . 66 Extending the Application with MEF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Print Itinerary Add-in Explained . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 What do you think of this book? We want to hear from you! Microsoft is interested in hearing your feedback so we can continually improve our books and learning resources for you. To participate in a brief online survey, please visit: microsoft.com/learning/booksurvey iii iv Table of Contents 3 From 2003 to 2010: Debugging an Application . . . . . . . . . . . . . . 81 Visual Studio 2010 Debugging Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Managing Your Debugging Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 New Threads Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 4 From 2003 to 2010: Deploying an Application . . . . . . . . . . . . . . 103 Visual Studio 2010 Web Deployment Packages . . . . . . . . . . . . . . . . . . . . . . 103 Visual Studio 2010 and Web Deployment Packages . . . . . . . . . . . . . 104 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Part II Moving from Microsoft Visual Studio 2005 to Visual Studio 2010 5 From 2005 to 2010: Business Logic and Data . . . . . . . . . . . . . . . 117 Application Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Plan My Night Data in Microsoft Visual Studio 2005 . . . . . . . . . . . . . . . . . 119 Data with the Entity Framework in Visual Studio 2010 . . . . . . . . . . . . . . . . 121 EF: Importing an Existing Database . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 EF: Model First . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 POCO Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 Putting It All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Getting Data from the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Getting Data from the Bing Maps Web Services . . . . . . . . . . . . . . . . 146 Parallel Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 AppFabric Caching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 6 From 2005 to 2010: Designing the Look and Feel . . . . . . . . . . . 153 Introducing the PlanMyNight.Web Project . . . . . . . . . . . . . . . . . . . . . . . . . . 153 Running the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 Creating the Account Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 Implementing the Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 Creating the Account View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Using the Designer View to Create a Web Form . . . . . . . . . . . . . . . . . . . . . 180 Extending the Application with MEF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 Print Itinerary Add-in Explained . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 7 From 2005 to 2010: Debugging an Application . . . . . . . . . . . . . 195 Visual Studio 2010 Debugging Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 Table of Contents Managing Your Debugging Session . . . . . . . . . . . . . . . . . . . . . . . . . . . 196 New Threads Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 Part III Moving from Microsoft Visual Studio 2008 to Visual Studio 2010 8 From 2008 to 2010: Business Logic and Data . . . . . . . . . . . . . . . 217 Application Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 Plan My Night Data in Microsoft Visual Studio 2008 . . . . . . . . . . . . . . . . . 219 Data with the Entity Framework in Visual Studio 2010 . . . . . . . . . . . . . . . . 222 EF: Importing an Existing Database . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 EF: Model First . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232 POCO Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 Putting It All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 Getting Data from the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 Parallel Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 AppFabric Caching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 9 From 2008 to 2010: Designing the Look and Feel . . . . . . . . . . . 251 Introducing the PlanMyNight.Web Project . . . . . . . . . . . . . . . . . . . . . . . . . . 251 Running the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 Creating the Account Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 Implementing the Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 Creating the Account View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270 Using the Designer View to Create a Web Form . . . . . . . . . . . . . . . . . . . . . 278 Extending the Application with MEF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 Print Itinerary Add-in Explained . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291 10 From 2008 to 2010: Debugging an Application . . . . . . . . . . . . . 293 Visual Studio 2010 Debugging Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 Managing Your Debugging Session . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 New Threads Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 v What do you think of this book? We want to hear from you! Microsoft is interested in hearing your feedback so we can continually improve our books and learning resources for you. To participate in a brief online survey, please visit: microsoft.com/learning/booksurvey Introduction Every time we get close to a new release of Microsoft Visual Studio, we can feel the excitement in the developer community. This release of Visual Studio is certainly no different, but at the same time we can feel a different vibe. In November 2009, at the Microsoft Professional Developer Conference in Los Angeles, participants had the chance to get their hands on the latest beta of this Visual Studio incarnation. The developer community started to see how different this release is compared to any of its predecessors. This might sound familiar, but Visual Studio 2010 constitutes, in our opinion, a big leap and is a true game changer in that it has been designed and developed from the core out. Looking at posts in the MSDN forums and many other popular developer communities also reveals that many of you—professional developers—are still working in previous versions of Visual Studio. This book will show you how to move to Visual Studio 2010 and try to explain why it’s a great time to make this move. Who Is This Book For? This book is for professional developers who are working with previous versions of Visual Studio and are looking to make the move to Visual Studio 2010 Professional. What Is the Book About? The book is not a language primer, language reference, or single-technology book. It’s a book that will help professional developers move from previous versions of Visual Studio (starting with 2003 and moving on up). It will cover the features of Visual Studio 2010 through a sample application. It will go through a lot of the exciting new language features and new versions of the most popular technologies without focusing on the technologies themselves. It will instead put the emphasis on how you get to those new tools and features from Visual Studio 2010. If you are expecting this book to thoroughly cover the new Entity Framework or ASP.NET MVC 2, this is not the book for you. If you want to read a book where the focus is on Visual Studio 2010 and on the reasons for moving to Visual Studio 2010, this is the book for you. vii viii Introduction How Will This Book Help Me Move to Visual Studio 2010? This book will try to answer that question by using a practical approach and by going through the new features and characteristics of Visual Studio 2010 from your point of view— that is, from the view of someone using Visual Studio 2005, for example. To be consistent for all points of view and to cover the same topics from all points of view, we decided to build and use a real application that covers many areas of the product rather than show you many disjointed little samples. This application is named Plan My Night, and we’ll describe it in detail in this Introduction. To help as many developers as we can, we decided to divide this book into three parts: ■ Part I is for developers moving from Visual Studio 2003 ■ Part II is for developers moving from Visual Studio 2005 ■ Part III is for developers moving from Visual Studio 2008 Each part will help developers understand how to use Visual Studio 2010 to create many different types of applications and unlock their creativity independently of the version they are using today. This book will focus on Visual Studio, but we’ll also cover many language features that make the move even more interesting. Each part will follow a similar approach and will include these chapters: ■ “Business Logic and Data” ■ “Designing the Look and Feel” ■ “Debugging the Application” For example, Part I, “Moving from Microsoft Visual Studio 2003 to Visual Studio 2010,” includes a chapter called “From 2003 to 2010: Debugging the Application.” Likewise, Part II, “Moving from Microsoft Visual Studio 2005 to Visual Studio 2010,” includes a chapter called “From 2005 to 2010: Debugging the Application.” Designing the Look and Feel These chapters will focus on comparing how the creation of the user interface has evolved through the versions of Visual Studio. They pay attention to the design surface, code editor, tools, and various controls, as well as compare UI validation methods. These chapters also tackle the topic of application extensibility. Introduction ix Business Logic and Data These chapters tackle how the application is structured and demonstrate the evolution of the tools and language features available to manage data. They describe the different application layers. They also show how the middle tier is created across versions and how the application will manage caching the data, as well as how to manage getting data in and from the database. Debugging the Application These chapters showcase the evolution of all developer aids and debugger tools, as well as compare the different ways to improve the performance of an application. They also discuss the important task of unit-testing your code. Deploying Plan My Night Part I, for developers using Visual Studio 2003, also includes one extra chapter, “From 2003 to 2010: Deploying an Application.” This chapter goes through the different ways to package, deploy, and deliver your application to your end users. The topic of updating and sending new bits to your customers is also discussed. We feel that Parts II and III, for developers using Visual Studio 2005 and Visual Studio 2008, respectively, didn’t require a chapter on deployment. What Is Plan My Night? Plan My Night (PMN) is an application that is self-describing, but just to make sure we’re on the same page, here’s the elevator pitch about PMN: Plan My Night is designed and developed to help its users plan and manage their evening activities. It allows the user to create events, search for activities and venues, gather information about the activities and the venues, and finally share or produce information about them. x Introduction As the saying goes, a picture is worth a thousand words, so take a look at the Plan My Night user interface in Figure I-1. FIGURE I-1  PMN’s user interface In its Visual Studio 2010 version, Plan My Night is built with ASP.NET MVC 2.0 using jQuery and Ajax for UI validation and animation. It uses the Managed Extensibility Framework (MEF) for extending the capabilities of the application by building plug-ins: for sharing to social networks, printing, e-mailing, and so on. We have used the Entity Framework to create the data layer and the Windows Server AppFabric (formerly known as codename “Velocity”) to cache data in memory sent to and obtained from the Microsoft SQL Server 2008 database. We figure that three pictures are better than one, so take a look at Figure I-2 for a diagram displaying the different parts and how they interact with each other and at Figure I-3 to see the different technologies used in building Plan My Night. Introduction FIGURE I-2  Plan My Night components and interactions FIGURE I-3  PMN 1.0 and the different technologies used in building it xi xii Introduction Why Should You Move to Visual Studio 2010? There are numerous reasons to move to Visual Studio 2010 Professional, and before we dive into the book parts to examine them, we thought it would be good to list a few from a highlevel perspective (presented without any priority ordering): ■ Built-in tools for Windows 7, including multitouch and “ribbon” UI components. ■ Rich, new editor with built-in Windows Presentation Foundation (WPF) that you can highly customize to suit how you work. Look at Figure I-4 for a sneak peek. ■ Multimonitor support. ■ New Quick Search, which helps to find relevant results just by quickly typing the first few letters of any method, class, or property. ■ Great support for developing and deploying Microsoft Office 2010, SharePoint 2010, and Windows Azure applications. ■ Multicore development support that allows you to parallelize your applications, and a new specialized debugger to help you track the tasks and threads. ■ Improvements to the ASP.NET AJAX framework, core JavaScript IntelliSense support, and the inclusion in Visual Studio 2010 of jQuery, the open-source library for DOM interactions. ■ Multitargeting/multiframework support. Read Scott Guthrie’s blog post to get an understanding of this great feature: multi-targeting-support-vs-2010-and-net-4-series.aspx. ■ Support for developing WPF ...
View Full Document

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture