.78 3 .NET Framework and Language Enhancements in 2008 79 An Overview of the Visual Studio 2008 IDE Enhancements by .NET Language.. It brought us code snippets, custom projecttemplates,
Trang 2Microsoft ®
Visual Studio 2008
U N L E A S H E D
800 East 96th Street, Indianapolis, Indiana 46240 USA
Mike Snell
Trang 3system, 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.
1 Microsoft Visual studio 2 Microsoft NET Framework 3 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
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
possi-ble, 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
Trang 4Introduction .1
Part I An Introduction to Visual Studio 2008 1 A Quick Tour of Visual Studio 2008 .7
2 A Quick Tour of the IDE .53
3 NET Framework and Language Enhancements in 2008 .79
Part II An In-Depth Look at the IDE 4 Solutions and Projects .105
5 Browsers and Explorers .135
6 Introducing the Editors and Designers .159
7 The NET Community: Consuming and Creating Shared Code .211
Part III Writing and Working with Code 8 Working with Visual Studio’s Productivity Aids .251
9 Refactoring Code .285
10 Debugging Code .315
Part IV 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
Trang 523 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 .1115
30 Team Foundation Build .1153
Index .1173
Trang 6Introduction 1
Part I An Introduction to Visual Studio 2008
Some Welcome Enhancements to the IDE .8
Use a Single Tool for Many Jobs .8
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
2 A Quick Tour of the IDE 53 Installing Visual Studio .53
Choosing a Language .53
Configuring Your Development Environment .54
Trang 7The 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
3 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
Trang 8Part II An In-Depth Look at the IDE
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
5 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
6 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
Trang 9Debugging 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
7 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 8 Working with Visual Studio’s Productivity Aids 251 Basic Aids in the Text Editor .253
Change Tracking .253
Coding Problem Indicators .254
Trang 10Syntax 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
9 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
Trang 11Encapsulate Field .312
Accessing Encapsulate Field .312
The Encapsulate Field Dialog Box .313
Summary .314
10 Debugging Code 315 Debugging Basics .316
The Scenario .316
The Many Phases of Debugging .316
Debugging the Application (Self-Checking) .317
Debugging Basics Summary .327
The Visual Studio Debugger .328
The Debug Menu and Toolbar .328
Debug Options .333
Stepping In, Out, and Over Code .334
Indicating When to Break into Code .340
Working with Tracepoints (When Hit Option) .348
Viewing Data in the Debugger .350
Using the Edit and Continue Feature .355
Advanced Debugging Scenarios .356
Remote Debugging .356
Debugging WCF Services .357
Debugging Multithreaded Applications .358
Debugging a Client-Side Script .361
Summary .362
Part IV Extending Visual Studio 11 Introducing the Automation Object Model 365 An Overview of the Automation Object Model .366
Object Model Versions .366
Automation Categories .368
The DTE/DTE2 Root Object .369
Solution and Project Objects .370
Controlling Projects in a Solution .373
Accessing Code Within a Project .374
Windows .377
Referencing Windows .377
Interacting with Windows .378
Text Windows and Window Panes .381
Trang 12The Tool Window Types .383
Linked Windows .392
Command Bars .394
Documents .398
Text Documents .400
Command Objects .412
Executing a Command .413
Mapping Key Bindings .414
Debugger Objects .415
Automation Events .416
Summary .417
12 Writing Macros 419 Recording a Macro .420
Using the Macro Explorer .421
Writing Macros with the Macro IDE .423
Working with Macro Projects .424
Writing a Macro .427
Debugging .430
Handling Events .431
Invoking Macros .436
Summary .440
13 Writing Add-ins and Wizards 441 Creating Your First Add-in Project .442
Setting Add-in Parameters .443
The Structure of an Add-in .452
The Life Cycle of an Add-in .452
Reacting to Commands .458
Managing Add-ins .460
A Sample Add-in: Color Palette .461
Getting Started .461
Creating the User Control .462
Finishing the Connect Class .466
Exposing Add-in Settings .469
Creating a Visual Studio Wizard .486
Examining the Wizard Structure .487
Creating an Add New Item Wizard .490
Summary .496
Trang 13Part V Creating Enterprise Applications
The Basics of an ASP.NET Website .500
Creating a New Web Application Project .500
Controlling Project Properties and Options .512
Creating Web Pages .518
Designing Your User Interface .526
Determining Page Layout and Control Positioning .528
Creating a Common Look and Feel .532
Creating a User-Configurable UI .550
Working with the ASP.NET Controls .561
An Overview of the ASP.NET Controls .561
The ASP.NET Standard Controls .563
Validation Controls .565
The Login Controls .567
Site Navigation Controls .571
Data Controls .573
User Controls .573
Summary .575
15 Building Windows Forms Applications 577 The Basics of Form Design .577
Considering the End User .578
Understanding the Role of UI Standards .579
Planning the User Interface .579
Creating a Form .581
The Windows Forms Application Project Type .581
Form Properties and Events .582
Adding Controls and Components .584
Control Layout and Positioning .586
Using Containers .590
Control Appearance and Behavior .594
Working with ToolStrip Controls .596
Displaying Data .603
Creating Your Own Controls .607
Subclassing an Existing Control .607
Designing a User Control .607
Creating a Custom Control .610
Summary .611
Trang 1416 Creating Richer, Smarter User Interfaces 613
The Windows Presentation Foundation Platform .613
Programming Model .615
Introducing the WPF Designer .619
XAML and Design Panes .620
Programming with WPF .623
Layout .624
Styles and Templates .631
Data Binding .635
Routed Events .637
Building a Simple Image Viewer Application .638
Starting the Layout .639
Storing the Images .641
Binding to the Images .643
Button Event Handlers and Image Effects .645
Path Selection with a Common Dialog .646
Summary .652
17 Creating Rich Browser Applications 653 Building Active Client Applications in Standard Browsers .653
The ASP.NET AJAX Controls .654
Creating an AJAX Page .656
The ASP.NET AJAX Control Toolkit Open-Source Library .660
Creating Unique, Rich Experiences on Windows via the Browser .668
Choosing Between WPF Standalone and WPF XBAP .669
Creating a WPF Browser Application .670
Security Considerations .671
Deploying a WPF Browser Application .676
Delivering Interactive Experiences Across Platforms .679
Getting Started with Silverlight .680
Creating a Silverlight Application .681
Using Silverlight on a Web Page .690
Summary .694
18 Working with Databases 697 Creating Tables and Relationships .697
Creating a New SQL Server Database .698
Defining Tables .700
Using the Database Diagram Designer .701
Working with SQL Statements .706
Writing a Query .706
Trang 15Developing Stored Procedures .710
Creating Triggers .714
Creating User-Defined Functions .715
Using Database Projects .716
Creating a Database Project .716
Auto-Generating Scripts .718
Executing a Script .719
Creating Database Objects in Managed Code .719
Starting a SQL Server Project .720
Creating a Stored Procedure in C# .720
Binding Controls to Data .724
An Introduction to Data Binding .724
Auto-Generating Bound Windows Forms Controls .725
Editing Typed DataSets .731
Manually Binding Windows Forms Controls .732
Data Binding with Web Controls .736
Object Relational Mapping .740
An Overview of LINQ .741
Mapping Using the O/R Designer .742
LINQ Code .745
Summary .748
19 Service-Oriented Applications 749 Service Fundamentals .750
Why ASP.NET Web Services and WCF .751
ASP.NET Web Service Applications .752
The ASP.NET Web Service Project Template .754
Creating an ASP.NET Web Service .757
Consuming an ASP.NET Web Service .772
Managing ASP.NET Web Service Exceptions .779
WCF Service Applications .780
The WCF Project Template .782
Creating a WCF Service .784
Configuring a WCF Service .790
Consuming a WCF Service .796
Hosting and Deploying a WCF Service .798
Summary .800
20 Embedding Workflow in Your Applications 801 Windows Workflow Fundamentals .802
The Components of a Workflow .802
Trang 16The Workflow Designer .804
The Workflow Item Templates .806
The Workflow Activities .809
Creating a Sequential Workflow .811
Designing the Workflow .811
Configure a CodeActivity .818
Configure the IfElse Activities and Use the RuleConditionEditor .819
Configure an InvokeWebService Activity .820
Configure the HandleExternalEvent Activities .821
Defining the Workflow Host and Client .824
Running Your Workflow .832
Creating a State Machine Workflow .834
Designing a State Machine Workflow .834
Initializing and Transitioning States .837
Defining the Client and Host .844
Running the State Machine Workflow .850
Summary .850
21 Developing Office Business Applications 853 An Overview of Office Extension Features .854
Office Features .855
Visual Studio Office Project Types .858
Creating an Office Add-in .859
Customizing the Ribbon .860
Customizing the Task Pane .863
Creating Outlook Form Regions .865
Creating an Office Document Extension .867
Hosting Controls .868
Creating an Actions Pane .870
Storing Data in the Data Cache .872
Implementing Your Own Smart Tags .874
Summary .878
Part VI Visual Studio Team System 22 Team Collaboration and Visual Studio Team System 881 A View of Software Development Projects .882
MSF Agile .883
MSF for CMMI .883
Introducing the Visual Studio Team System .885
Visual Studio Team System Architecture Edition .887 Visual Studio Team System Development Edition 888
Trang 17Visual Studio Team System Test Edition .890
Visual Studio Team System Database Edition .890
Team Foundation Server .892
Summary .894
23 Managing and Working with Team Projects 895 Anatomy of Team Foundation Server .895
The Application Tier .896
The Data Tier .898
Security .899
Managing a Team Project .901
Creating a New Team Project .902
Adding Users to a Project Team .905
Controlling Project Structure and Iterations .910
Contributing to a Project Team .912
Connecting to a Team Foundation Server .912
Using Team Explorer .913
Using the Project Portal .914
Using Microsoft Office .915
Using Project Alerts .917
Working with Project Reports .917
Summary .920
24 Source Control 921 The Basics of Team Foundation Source Control .922
Basic Architecture .922
Security Rights and Permissions .923
Getting Started with Team Foundation Source Control .924
Configuring Visual Studio .925
Using the Source Control Explorer Window .926
Managing Workspaces .927
Adding Files to Source Control .930
Editing Files Under Source Control .932
Retrieving a File from the Source Repository .932
Checking in Your Changes .933
Understanding the Concept of Changesets .939
Shelving Your Code .940
Merging Changes .942
Branching and Merging .944
Branching .946
Merging .947
Trang 1825 Work Item Tracking 949
Understanding Work Items .950
Understanding the Role of Work Items and the SDLC .950
Picking the Work Item Set for Your Project .951
Identifying Work Item Commonalities .956
Using Team Explorer to Manage Work Items .965
Creating a New Work Item .965
Finding and Filtering Work Items .967
Understanding Team Role Perspectives .971
Project Vision .971
Project Manager .972
Business Analyst .979
Developer .980
Tester .983
Customizing Work Items .986
Seeding the Process with Work Items .987
Customizing an Existing Work Item .991
Summary .994
26 Development Edition 995 Visually Developing Code .996
The Class Designer .996
Adding Items to the Diagram .998
Defining Relationships Between Classes .999
Defining Methods, Properties, Fields, and Events .1002
Developer Unit Testing .1004
A Sample Unit Test .1006
Writing Effective Unit Tests .1006
Using Unit Test Classes and Methods .1007
Creating Unit Tests .1008
Running Unit Tests .1010
Code Coverage Analysis .1014
Performance Profiling .1015
Creating a Performance Session .1016
Configuring a Session .1018
Session Targets .1023
Reports .1023
Understanding Performance Reports .1024
Code Analysis .1034
Configuring Rules to Enforce .1035
Treating Rule Violations as Coding Errors .1036
Trang 19Treating Rule Violations as Coding Errors .1036
Suppressing Rules .1037
Doing the Analysis .1039
Viewing the Results .1039
Prescriptive Guidance for Remediation .1041
Code Metrics .1041
The Measurements .1042
Running Code Metrics .1042
Working with the Results .1042
Summary .1045
27 Architecture Edition 1047 Team Architect Artifacts .1048
Project Templates .1048
Item Templates .1049
Designing Your Application .1050
Working with the Application Diagram .1051
Defining a System .1059
System Diagram .1060
Defining Your Infrastructure .1062
Logical Datacenter Diagram .1063
Deploying Your Application .1071
Deployment Diagram .1072
Validating Deployment .1073
Deployment Report .1074
Implementing Your Application .1074
Setting Implementation Properties .1075
Generating Projects .1075
Summary .1077
28 Test Edition 1079 Creating, Configuring, and Managing Tests .1080
Test Projects .1080
Test Items .1082
Managing Tests .1083
Testing Configuration .1086
Web Testing .1086
Recording a Web Test .1086
Managing Web Test Requests .1088
Running the Web Test and Viewing Results .1089
Trang 20Seeding a Web Test with Data .1089
Extracting Values from Web Tests .1096
Requesting Validation Rules .1097
Load Testing .1100
Creating a Load Test .1100
Reviewing and Editing a Load Test .1106
Running Load Tests and Reviewing Results .1107
Manual Tests .1109
Creating a Manual Test .1109
Executing a Manual Test .1109
Generic Tests .1110
Ordered Tests .1112
Creating an Ordered Test .1112
Summary .1113
29 Database Edition 1115 The Database Project System .1116
Creating a Database Project .1117
The Schema View .1124
Comparing Schemas .1126
Viewing Object Definitions .1128
The Schema Update Script .1129
Comparison Options .1130
Comparing Data .1131
Viewing Record-Level Details .1132
Previewing and Executing the Update Script .1134
Rename Refactoring .1135
Rename Options .1135
Previewing the Schema Changes .1136
Unit Tests .1137
Creating Unit Tests .1137
The Database Unit Test Designer .1139
Generating Data .1142
Creating a Data Generation Plan .1142
Previewing the Generated Data .1144
Generating the Data .1149
Building and Deploying .1149
Summary .1151
Trang 2130 Team Foundation Build 1153
An Overview of Team Foundation Build .1154
Team Foundation Build Architecture .1154
Creating a New Build .1158
Naming the Build .1158
Selecting Project Files to Build .1158
Defining the Build Project File .1159
Defining the Build Retention Policy .1162
Defining the Build Agent Configuration .1162
Scheduling the Build or Setting Build Triggers .1163
Editing a Build Definition .1165
The TFSBuild.proj Project File .1165
The Role of MSBuild .1166
Starting a Build .1166
Monitoring and Analyzing Builds .1167
Introducing the Team Build Explorer .1168
The Build Report .1170
Summary .1171
Trang 22Lars Powers is an ISV Technical Advisor on the Microsoft Developer and Platform
Evangelism team He works with Microsoft’s largest global ISV partners to help them craftsolutions on top of Microsoft’s next-generation technologies Prior to joining Microsoft,Lars was an independent consultant providing training and mentoring on the NET platform
Mike Snell runs the Solutions division at CEI (www.ceiamerica.com) Mike and his team
deliver architecture, consulting, and mentoring to clients looking to build great enterpriseand commercial software Mike is also a Microsoft Regional Director
(www.theregion.com)
Trang 23To Cheryl, Kelsey, and Carson: a simple “thank you” for being there
when I needed you.
—Lars Powers
To Carrie, Allie, and Ben Thanks for your understanding for the many long weekends spent in my office and for having to split up the rock band to get this book done We can fire up the Xbox again.
—Mike Snell
Trang 24We would like to thank the great team at Sams Publishing for their many valuable butions and helping us get this book completed This includes our copy editor, CheriClark; our technical editor, Todd Meister; our development editor, Mark Renfrow; our twoproject editors, Kristy Hart and Anne Goebel; and, finally, our two acquisitions editors,Brook Farling and Neil Rowe.
contri-Mike Snell: I would also like to thank the architects on my team for their insight and forhearing me out on a number of topics that are included in this book In addition, I wouldlike to thank my good friend and co-author, Lars Powers This was yet another great expe-rience working together
Lars Powers: I would like to thank the various members of the Microsoft Developer andPlatform Evangelism team worldwide I can honestly say that this is the smartest, mostmotivated group of folks that I have ever worked with, and it is my pleasure to call thisteam my professional home I’d also like to thank my co-author, Mike, for first convinc-ing me to embark on this project and then for being a solid peer and partner during thewriting and editing process Lastly, and with apologies to Jason Olsen: For the Developers!And finally, we would like to thank the various teams at Microsoft responsible for bring-ing Visual Studio and the Visual Studio Team System concepts to life
Trang 25As the reader of this book, you are our most important critic and commentator We value
your opinion and want to know what we’re doing right, what we could do better, whatareas you’d like to see us publish in, and any other words of wisdom you’re willing topass our way
You can email or write me directly to let me know what you did or didn’t like about thisbook—as well as what we can do to make our books stronger
Please note that I cannot help you with technical problems related to the topic of this book, and that due to the high volume of mail I receive, I might not be able to reply to every message.
When you write, please be sure to include this book’s title and author, as well as yourname and phone or email address I will carefully review your comments and share themwith the author and editors who worked on the book
Executive EditorSams Publishing
800 East 96th StreetIndianapolis, IN 46240 USA
Reader Services
Visit our website and register this book at www.informit.com/title/9780672329722 forconvenient access to any updates, downloads, or errata that might be available for thisbook
Trang 26The release of Visual Studio 2005 and Visual Studio Team Systems marked a major sion to the NET development experience It brought us code snippets, custom projecttemplates, refactoring, data binding wizards, smart tags, modeling tools, automatedtesting tools, and project and task management—to name just a few features.
revi-Visual Studio 2008 builds on these tools and provides additional core changes and tions to the Visual Studio integrated development environment (IDE) The languages havemany new improvements, the Framework has a number of additions, and the tools havebeen significantly enhanced For instance, Visual Studio 2008 includes such things asWindows Presentation Foundation (WPF) for building richer client solutions, WindowsCommunication Foundation (WCF) to help build more dynamic service-oriented solu-tions, and Windows Workflow Foundation (WF) to enable structured programmingaround business processes In addition, there are language enhancements such as theLanguage Integrated Query (LINQ) and team systems enhancements such as code metrics,performance profiling, and a revised team build system All of these tools are meant toincrease your productivity and success rate This book is meant to help you unlock themany tools built into Visual Studio so that you can realize these gains
addi-Who Should Read This Book?
Developers who rely on Visual Studio to get work done will want to read this book Itprovides great detail on the many features inside the latest version of the IDE The bookcovers all the following key topics:
Understanding the basics of solutions, projects, editors, and designers
Writing macros, add-ins, and wizards
Debugging with the IDE
Refactoring code
Sharing code with team members and the larger community
Writing ASP.NET applications
Writing and consuming web services and using the Windows CommunicationFoundation (WCF)
Coding with Windows forms and with Windows Presentation Foundation (WPF)
Working with data and databases
Creating and hosting workflow-based applications using Windows Workflow
Foundation (WF)
Trang 27Using team collaboration and the Visual Studio Team System products
Modeling applications
Testing applications at both the system and unit test level
Managing source code changes and builds
This book is not a language book; it is a tools book If you are trying to understand VisualBasic or C#, you will want a companion book that focuses on those subjects If you canwrite C# or Visual Basic code, this book will radically help you to optimize your produc-tivity with Visual Studio Again, this book is not a primer on the NET languages
However, we do cover the new language features (such as LINQ) in both C# and VisualBasic We also try to provide simple examples that can be read by developers of bothlanguages By and large, however, this book has one primary focus: detailing and explain-ing the intricacies of the Visual Studio 2008 IDE to enable developers to be more produc-tive
How Is This Book Organized?
You can read this book cover to cover, or you can pick the chapters that apply most toyour current need We sometimes reference content across chapters, but for the most part,each chapter can stand by itself This organization allows you to jump around and read astime (and interest) permits There are four parts to the book; each part is described next.Part I: An Introduction to Visual Studio 2008
The chapters in this part provide an overview of what to expect from Visual Studio 2008.Readers who are familiar only with prior versions of Visual Studio will want to reviewthese chapters In addition, we cover the new language enhancement for the 2008versions of VB and C#
Part II: An In-Depth Look at the IDE
This part covers the core development experience relative to Visual Studio It providesdevelopers with a base understanding of the rich features of their primary tool The chap-ters walk through the many menus and windows that define each tool We cover the baseconcepts of projects and solutions, and we explore in detail the explorers, editors, anddesigners
Part III: Writing and Working with Code
Part III builds on the topics discussed in Part II by digging into the powerful productivityfeatures of Visual Studio 2008 These chapters investigate the developer productivity aidsthat are present in the IDE, and discuss how to best use Visual Studio for refactoring anddebugging your code
Trang 28Part IV: Extending Visual Studio
For those developers interested in customizing, automating, or extending the VisualStudio IDE, these chapters are for you We explain the automation model and then docu-ment how to use that API to automate the IDE through macros We also cover how youcan extend the IDE’s capabilities by writing your own add-ins
Part V: Creating Enterprise Applications
Part V focuses on how to work with the IDE tools to write your applications Each chapterprovides an in-depth overview of how to use Visual Studio to help you design and
develop an application We cover writing applications using ASP.NET, web services andWCF, Windows forms, WPF, WF, and working with data and databases
Part VI: Visual Studio Team System
Finally, Part VI discusses the special set of Visual Studio versions collectively referred to asVisual Studio Team System (VSTS) We devote an entire chapter to each individual VSTSedition: Development Edition, Architecture Edition, Test Edition, and Database Edition
We also explore, in-depth, the key concepts of team collaboration, work item tracking,and version control using the VSTS client editions in conjunction with the Team
Foundation Server product And lastly, we discuss the concept of automated builds withinthe context of Visual Studio Team System
Conventions Used in This Book
The following typographic conventions are used in this book:
Code lines, commands, statements, variables, and text you see onscreen appears in amonospacetypeface
Placeholders in syntax descriptions appear in an italic monospacetypeface You replacethe placeholder with the actual filename, parameter, or whatever element it represents
Italics highlight technical terms when they’re being defined.
A code-continuation icon is used before a line of code that is really a continuation of thepreceding line Sometimes a line of code is too long to fit as a single line on the page Ifyou see ➥ before a line of code, remember that it’s part of the line immediately above it.The book also contains Notes, Tips, and Cautions to help you spot important or usefulinformation more quickly
Trang 30An Introduction to
Visual Studio 2008
IN THIS PART
CHAPTER 1 A Quick Tour of Visual Studio 2008 7
CHAPTER 3 NET Framework and Language
Trang 32A Quick Tour of Visual
Studio 2008
Some Welcome Enhancements
to the IDE
Develop User Applications
Write Connected, Oriented Solutions
Service- Work with Data
The Visual Studio Product Line
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
revi-sion 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,
mile-stone 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
Trang 33programming models, unfamiliar terms, fresh dialog boxes, and new ways to view code; itcan be hard to find your footing on what seems to be unfamiliar ground This chapterrepresents what to expect as a first encounter with Visual Studio 2008 We will first do arun-through of the tool to help you get your bearing We’ll then help you sort throughthe 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, andcreating that first project It also serves to familiarize you with the basics of the IDE InChapter 3, “.NET Framework and Language Enhancements in 2008,” we will cover thelanguage and NET Framework enhancements that are part of the 2008 release
Some Welcome Enhancements to the IDE
Visual Studio 2008 and the NET Framework 3.5 introduce hundreds of new features to analready full-featured toolset This latest version is about increasing developer productivitywhen writing applications targeted at the new version of the NET Framework Thisincludes expanded project types, a reduction in mundane tasks, and ever-evolving aspects
of team-oriented software engineering This section and those that follow highlight theseenhancements 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
Use a Single Tool for Many Jobs
Many of us work in environments that include applications built on various versions ofthe NET Framework This becomes even more prevalent as more versions are released Forexample, 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 applicationrequires occasional maintenance, you do not want to have to keep two versions of VisualStudio on your machine
Visual Studio 2008 supports the ability to target a specific version of the NET Frameworkfor an application This means you can use a single tool to develop against many applica-tions built on various NET Framework flavors Setting the NET Framework version of anapplication will appropriately set the toolbox, project types, available references, and evenIntelliSense inside the IDE to be in synch with the chosen NET Framework version Figure1.1 shows creating a new application with Visual Studio 2008 and selecting the NETFramework version (upper-right corner)
Notice the Add Reference dialog in Figure 1.2 It shows adding a reference to a Windowsapplication 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)
Trang 34You can also decide to move your application to a different (hopefully newer) version ofthe NET Framework You can do so inside the project properties dialog (right-click yourproject 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, ence, your toolbox, and more to the newly selected target framework
Trang 35FIGURE 1.3 Resetting the target framework of a Windows application.
Of course, you can use Visual Studio 2008 to open an existing application built on a priorversion of the NET Framework When doing so, you have the option of upgrading orkeeping it tied to the existing NET Framework version These features serve to help youupgrade to the advantages of 2008 and continue to work with applications built on anolder version of the NET Framework
The IDE Navigator
Developers can now navigate open windows in the IDE without touching a mouse Thiskeeps 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
Trang 36FIGURE 1.4 The IDE Navigator in action.
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 forthe 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 switchingwithout 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 thedialog and navigate open code Windows and active tool Windows Figure 1.4 shows theresult 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.NextDocumentWindowNavandWindow.PreviousDocumentWindowNav
Alternatively, you can access the IDE Navigator directly using Alt+F7 This brings up thetool with the active tool windows list selected You can jump between the lists using theright- and left-arrow keys
Improved Docking
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 izations that make this process very simple Figure 1.5 shows an example of docking the
Trang 37visual-FIGURE 1.5 Improved window docking.
Server Explorer window on top of the Toolbox pane You can see that there are options tomove this window to the left of the toolbox, below it, and so on Selecting each optionshows a visual representation of the results before you release your mouse button
Standard Dialogs
Another welcome change to the IDE is the use of Windows standard dialog boxes fordoing such tasks as opening a file, saving something, or printing code In prior version ofVisual Studio, the IDE had its own versions of these common tasks However, this onlymade things confusing because most Windows users are accustomed to working usingspecific tools
As an example, consider Figures 1.6 and 1.7 Figure 1.6 is the Open File dialog in VisualStudio 2005 This dialog was specific to Visual Studio Figure 1.7 shows the same dialog inVisual Studio 2008 Notice that the dialog is the same dialog you would get in any otherWindows-based application
Choose Your Font
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 forthe entire IDE to the selection of your choice Figure 1.8 shows selecting this option fromthe list
Trang 38Changing 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
Keep Your Settings
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 allowyou to migrate these settings on startup
Trang 39FIGURE 1.8 Setting the Environment Font.
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 isavailable from the Tools menu in both Visual Studio 2005 and 2008 It is a wizard thatallows you to import settings, export them to a file, or reset your settings to one of theIDE defaults Figure 1.10 shows an example of exporting settings
Trang 40When you export or import settings, you can select those you want to apply Figure 1.11shows the second step in the export process Notice you can pick and choose those itemsyou want to export