Post on 27-May-2018
Visual Studio® 2010 and .NET 4
SIX-IN-ONE
Istvan Novak
Andras Velvart
Adam Granicz
Gyorgy BalassyAttila HajdrikMitchel Sellers
Gaston C. Hillar
Agnes Molnar
Joydip Kanjilal
WILEY
Wiley Publishing, Inc.
CONTENTS
INTRODUCTION xxxiii
CHAPTER 1: HISTORY OF VISUAL STUDIO 3
Roots 4
The First Breakthrough: Visual Basic 4
Other Languages and Tools 4
Visual Studio 97 and 6.0 5
Visual Studio.NET 2002 and 2003 5
Visual Studio 2005 7
Visual Studio 2008 8
Visual Studio 2010 10
Changes in Editions 10
What's New in Visual Studio 2010 12
Shift to WPF 12
Summary 13
CHAPTER 2: VISUAL STUDIO Ul ENHANCEMENTS 15
Basic IDE Overview 15
Exploring the Start Page 15
Understanding Window Management 16
New Project Dialog Window 17
Creating New Projects in a New Way 19
Using the Add Reference Dialog Window 19
Using the Extension Manager 20
Exploring New Daily Development Features 20
Exploring the Code Editor Window 20
Code Navigation 22
Generate From Usage 24
Exploring the Visual Designers 25
WPF Designer 26
XML Schema Designer 27
New Tools for Architects 27
Summary 29
CHAPTER 3: VISUAL STUDIO CODE SNIPPETS 31
Understanding Code Snippets 32
Using Code Snippets 34
HTML, SQL, and JScript Code Snippets 37
Creating Code Snippets 38
Creating a Simple Code Snippet 38
The Code Snippet Fife Structure 41
Managing Code Snippets 51
The Code Snippet Manager 52
Code Snippet Storage 53
Adding and Removing Snippets 54
Importing Snippets 54
Advanced Code Snippet Features 56
Multiple Snippets in a File 56
Code Snippets in Other Languages 58
Building Online Code Snippet Providers 59
Snippet Editors 59
Export as Code Snippet Add-In 60
Snippet Designer 61
Snippet Editor 62
Summary 63
CHAPTER 4: VISUAL STUDIO TEMPLATES 65
The Role of Templates 66
Project Templates 67
Item Templates 69
Creating Templates 70
Creating a Simple Project Template 71
Creating a Simple Item Template 76
Template Storage Structure 81
Template Folders 82
The Template Manifest File 84
Customizing Templates 98
Template Parameters 98
Custom Template Parameters 99
Wizards 101
Deploying Templates 110
Exporting and Importing Templates 111
Creating a Template Installation Kit 114
Summary 125
CHAPTER 5: GETTING THE MOST OUT OF THE IDE 127
Window Management 128
Visual Studio Window Architecture 128
Tool Windows 131
Document Windows 132
Arranging Windows 134
Customizing Menus and Toolbars 138
The Customize Dialog 139
Adding Menus and Commands 140
Creating and Rearranging Toolbars 144
Context Sensitivity 145
IDE Configuration 145
The Options Dialog 145
Changes in Option Pages 147
Visual Studio Settings 150
Reducing Efforts with Keyboard Shortcuts 155
Command Routing and Command Contexts 155
Working with Keyboard Shortcuts 157
Working with Keyboard Mapping Schemes 160
Custom Start Pages 162
Creating Your First Custom Start Page 163
Changing the StartPage.xaml File 173
Accessing the Visual Studio Context 176
Accessing the Visual Studio Object Model 182
A Few More Points About Start Pages 186
Customizing the Toolbox 186
A Lap Around the Toolbox 186
Customizing Toolbox Tabs 189
Adding Items to the Toolbox 190
A Few More Points About Toolbox Customization 193
Visual Studio Gallery 193
Browsing the Visual Studio Gallery 194
Downloading and Installing Components 196
Adding Your Own Contributions to the Gallery 197
Working Together with the Community 198
Summary 198
CHAPTER 6: VISUAL STUDIO EXTENSIBILITY 201
The Visual Studio Shell and Packages 202
Package Integration 203
Extensibility Out of the Box 204
Extending Visual Studio by Customization 204
Using Macros to Automate Common Tasks 208
Visual Studio Add-lns 209
Extensions with Visual Studio SDK 210
The Full Power of Extensibility 210
Visual Studio Package Development 211
Editor Extensibility 212
Creating Visual Studio Macros 213
Understanding the Structure of Macros 213
Using the Macros IDE 218
Recording and Developing Macros 221
Macro Samples 225
Creating Visual Studio Add-lns 229
Add-In Architecture 229
Creating a Simple Add-in 230
Using the Automation Model 239
Going on with Add-In Development 241
Visual Studio Packages in a Nutshell 242
Creating a Package with a Simple Menu Command 242
Debugging the Package 254
Extending the New Editor 255
Extending the Editor with the Managed Extensibility Framework 256
Editor Extensibility Points 258
Creating a Simple Classifier 250
Summary 275
CHAPTER 7: .NET FRAMEWORK VERSION HISTORY 279
Before the .NET Framework 279
Win/Win32 Programming in C 279
C++ Programming 280
Programming in Visual Basic 280
Programming in Delphi 281
COM Programming 281
The Origin and Goals of the .NET Framework 282
Evolution of the .NET Framework 283
.NET Framework 1.0 286
.NET Framework 1.1 286
.NET Framework 2.0 286
.NET Framework 3.0 287
.NET Framework 3.5 287
.NET Framework 4.0 288
.NET Compact Framework 289
.NET Micro Framework 289
.NET Framework Architecture 289
Common Language Run-time (CLR) 290
Base Class Library 291
Services of the .NET Architecture 292
Main Benefits of the .NET Framework 293
Summary 294
CHAPTER 8: MODERN Ul FRAMEWORKS (WPF AND SILVERLIGHT) 297
The Importance of User Experience 297
Developers Are from Vulcan, Designers Are from Venus 299
A New Generation of Presentation Frameworks 301
The Ten Pillars of Silverlight 303
XAML 304
Tools for Working with Silverlight (and WPF) 313
Layout 315
Data Binding 322
Styles 330
Templates 332
Animations 341
Media 345
Networking 352
Other Features 355
Windows Presentation Foundation 359
WPF Features not Available in Silverlight 361
Choosing Between WPF and Silverlight 366
Designer - Developer Cooperation in Silverlight and WPF 367
A Common Solution Format 367
Blendability 368
Design Time Sample Data in Blend 369
SketchFlow 370
Triggers, Actions, and Behaviors 371
Model-View-ViewMode! Pattern 372
Summary 373
CHAPTER 9: WINDOWS COMMUNICATION FOUNDATION (WCF) 375
WCF Versus ASMX Web Services 375
A Quick Look at SOA 376
Service 377
Service Provider 377
Service Consumer(s) 377
Service Registry 377
Service Contract 377
Service Proxy 378
Service Lease 378
Message 378
Service Description 378
Advertising and Discovery 378
Building Blocks of the WCF Architecture 378
Getting Started With WCF 381
Creating the WCF Service 382
Defining Data Contracts 386
Specifying the Binding Information 387
Hosting the WCF Service 388
Creating the Service Proxy 389
Creating the Service Client — The Service Consumer 391
Working with an Ajax-Enabled WCF Service 392
REST and WCF 394
Implementing a WCF Service Declaratively 394
Defining the Service Contract 395
Hosting the Service 396
Implementing the Service Logic Declaratively 396
Summary 398
CHAPTER 10: ENHANCEMENTS TO THE .NET CORE FRAMEWORK 399
Changes in Common Language Run-time 400
In-Process Side-By-Side Execution 400
DLR Integration 402
Type Equivalence 411
Parallel Computing 415
The Challenge of Many-core Shift 416
The Microsoft Approach 418
Parallel LINQ 421
Task Parallel Library 428
Code Contracts 455
Managed Extensibility Framework 463
The Challenge 463
A Simple MEF Example 465
Basic MEF Concepts 471
Composition 477
A Few More Points on MEF 486
Summary 487
CHAPTER 11: ENHANCEMENTS TO THE .NET WORKFLOW
FRAMEWORK 489
An Introduction to WF 4.0 490
The Workflow Design Surface 491
The Hello Workflow Application 492
Creating Flowcharts and Coded Workflows 499
Flowcharts in WF 4.0 500
Code-Only Workflows 505
Workflow Architecture 509
WorkflowApplication and Hosts 510
Activities 511
Extensions 512
Workflow Activity Model Changes 513
Workflow Activity Library 517
Primitive Activities 518
Flow Control Activities 518
Workflow Run-Time Activities 520
Flowchart-Specific Activities 521
Error-Handling Activities 522
Transaction-Handling Activities 523
Collection-Handling Activities 524
Messaging Activities 525
Using the Compensating Transaction Model 527
The ConferenceWorkflow Example 527
Implementing Cancellation, Confirmation, and Compensation 528
Cancellation 530
Compensation 530
Persistence and Human Interactions 532
The DomainNameWorkflow Project 533
Workflow Tracking 544
Workflow Services 551
Creating a Workflow Service 551
Using WorkflowServiceHost 553
Summary 562
CHAPTER 12: ENHANCEMENTS TO THE .NET DATA FRAMEWORK 563
Language Integrated Query (LINQ) 563
LINQ Operators 564
LINQ Implementations 566
Parallel LINQ (PLINQ) 572
Entity Framework 573
Entity Framework Architecture 573
The Entity Data Source Control 579
Choosing Between LINQ to Entities and LINQ to SQL 579
Summary 579
CHAPTER 13: ENHANCEMENTS TO THE .NET COMMUNICATION
FRAMEWORK 581
Enhancements in WCF Framework 3.5 581
Enhancements in WCF Framework 4.0 583
Simplified Configuration 583
Standard Endpoints 585
Discovery 586
REST Improvements 588
Routing Service 589
Summary 592
CHAPTER 14: .NET CHARTING COMPONENTS 593
Creating Charts 594
Creating a Simple Chart 594
Adding Data to the Chart Programmatically 598
Adding Charts to WPF Applications 603
Using Chart Controls 605
Elements of a Chart 606
The Chart Class 607
Chart Types 609
Chart Coordinate System 617
Three-Dimensional Charts
Appearance of Chart Elements
Axes and Related Chart Elements
Data Points
Advanced Chart ManipulationAnnotations
Binding Data to Series
The DataManipulator class
More Chart Manipulations
Summary
619
621
623
630
633
633
638
641
648
649
CHAPTER 15: ASP.NET VERSION HISTORY 653
Development of the Web and Web Development 653
Enter ASP 654
EnterASP.NET 655
ASP.NET Version History 657
ASP.NET 1.0 659
ASP.NET 1.1 659
ASP.NET 2.0 659
ASP.NET 3.0 664
ASP.NET 3.5 665
ASP.NET 3.5 SP1 667
ASP.NET 4.0 667
Summary 668
CHAPTER 16: ASP.NET CHARTING CONTROLS 669
Creating Charts 670
Adding a Chart Control to a Page 670
Setting up Charts in an Event Handler Method 674
Binding Data to the Chart 676
Rendering ASP.NET Charts 679
Image URL Rendering 680
Using Charts with Legacy Web Sites 683
Binary Stream Rendering 684
Chart State Management 688
Saving Chart State 688
Advanced Chart State Management 690
User Interactivity 694
Using Tooltips 694
Handling Clicks on Data Points 696
Interactivity With Ajax 697
A Few More Points on User Interactivity 709
Summary 709
CHAPTER 17: ASP.NET DYNAMIC DATA 711
Creating a New Dynamic Data Web Site 711
Working Against a Data Model 711
Displaying Data from Existing Tables 716
Creating Simple CRUD Applications 718
Creating a Dynamic Data Application for Master-Detail Relationships 725
Working to Modify Implementation to Fit Business Needs 730
Understanding Dynamic Data's Structure 730
Customizing the Look and Feel 732
Working with Page Templates 735
Working with Field Templates 738
Working with Entity Templates 741
Working with Filter Templates 744
Creating Custom Pages 746
Customizing Validations 747
Summary 750
CHAPTER 18: ASP.NET MODEL VIEW CONTROLLER (MVC) 751
Introduction to MVC 752
Similar Design Patterns 753
Microsoft and the Web Platform 753
What Is Microsoft ASP.NET MVC 2? 754
Extensibility in MVC 760
Creating an MVC 2 Application 761
The Project Structure 763
How Does it Work? 764
Adding New MVC 2 Pages 771
Create a Database 771
Create a Model 772
Listing Books 773
Adding Book Actions 779
Customization in MVC 2 790
Model Binding 790
Validation 795
Ul Customization 804
Routing Details 816
Controller Factory 816
Influencing the Execution Flow 817
Authorization 819
Action and Result Filtering 821
Exception Filtering 822
ActionResult 822
Testing with MVC 2 824
Refactoring AcmeLibrary 824
Creating and Running Unit Tests 831
A Few More Points on MVC 2 834
Areas 834
Metadata Providers 834
Value Providers 834
Model Binders 835
Child Actions 835
Asynchronous Controllers 835
Summary 835
CHAPTER 19: ASP.NET AJAX IMPROVEMENTS 837
Understanding Ajax 838
The XMLHttpRequest Object 839
ASP.NET and Ajax 840
Using the ASP.NET Ajax Server Controls 841
Refactoring the Framework Libraries 844
Using the Microsoft CDN 846
Using the Microsoft Ajax Library 848
Working with DOM Elements 852
The Script Loader 855
Client-Side Data Binding with Templates 859
Advanced Data-Binding Scenarios 872
Working with Server-Side Data 878
Summary 892
CHAPTER 20: ASP.NET AJAX CONTROL TOOLKIT AND JQUERY 893
First Look at the Ajax Control Toolkit 894
Installing the Ajax Control Toolkit 894
Creating a Simple Web Application with the Toolkit 896
Using the Controls of the Toolkit 908
New Server Controls 915
Control Extenders 938
Animations 957
The jQuery Library 962
"Hello, World" with jQuery 963
Selectors and Filters 965
Chaining and Utility Functions 970
Eventing Model and Event Handlers 971
Visual Effects and Animations 975
jQuery Ajax Features 976
Summary
isip»"j^^s^ipsiSfii|f
977
CHAPTER 21: HISTORY OF VISUAL BASIC
Ifllllllfiflil'
981
The Roots of Visual Basic 982
Structured and Unstructured BASIC 982
Moving to "Visual" 984
Visual Basic in the 1990s 985
Visual Basic in the .NET Framework 986
Design Goals and Debates 986
Visual Basic .NET (7.0) and .NET 2003 (7.1) 987
Visual Basic 2005 (8.0) 989
Visual Basic 2008 (9.0) 997
Summary 1005
CHAPTER 22: VISUAL BASIC 10.0 LANGUAGE IMPROVEMENTS 1007
New Productivity-Improving Syntax 1008
Implicit Line Continuation 1008
Auto-Implemented Properties 1010
Collection Initializers 1012
Multiline Lambda Expressions 1018
Working with Dynamic Objects 1020Late Binding in Visual Basic 2010 1021
Accessing an IronPython Library 1023
Variance 1026
Type Substitution 1026
Variance in Visual Basic 2010 1029
A Few More Points on Variance 1033
Summary 1038
CHAPTER 23: HISTORY OF C# 1041
The Evolution of C# 1041
Design Goals 1042
Short History 1042
Implementations 1043
C# 1.0 1044
Type System 1044
Memory Management 1045
Syntactic Sugar 1046
C# 1.1 1047
C# 2.0 1047
Generic Types 1048
Partial Types 1050
Static Classes 1051
Iterators 1052
Anonymous Methods 1052
Delegate Inference 1053
Delegate Covariance and Contravariance 1053
Nullable Types 1054
Property Accessors 1055
Null-Coalesce Operator 1056
Namespace Aliases 1056
C# 3.0 1056
Local Variable Type Inference 1057
Extension Methods 1057
Anonymous Types 1058
Lambda Expressions 1059
Query Expressions 1060
Expression Trees 1061
Automatic Properties 1062
Object Initializers 1062
Collection Intializers 1063
Partial Methods 1°63
Summary 1064
CHAPTER 24: C# 4.0 LANGUAGE IMPROVEMENTS 1065
Pains with Interoperability 1066
Creating the PainWithOffice Application 1066
Frustrating Issues 1069
Remove the Pain 1070
Dynamic Lookup 1072
Dynamic Binding 1°72
The dynamic Type 1073
Dynamic Operations 1074
The Dynamic Language Run-time 1077
Named and Optional Parameters 1078
Using Optional Parameters 1079
Using Named Parameters 1081
Overload Resolution 1082
COM-Specific Interoperability Features 1084
Dynamic Import 1084
Omitting ref from Parameters 1084
Indexed Properties 1085
Compiling Without PIAs 1086
Variance 1087
Type Substitution 1087
Bird's-Eye View of Variance 1089
Variance in C# 4.0 1090
A Few More Points on Variance 1094
Summary 1099
CHAPTER 25: VISUAL F# AND THE OTHER .NET LANGUAGES 1103
A Brief History of F# 1104
F# at First Glance 1105
Trying Things Out with F# 1106
Understanding Syntax 1107
Your First F# Project 1112
Programming with F# 1113
Namespaces and Modules 1113
Attributes 1115
Literals and Bindings 1115
Expressions 1120
Values and F# Types 1124
Type Augmentations 1137
Computation Expressions 1138
Sequences 1141
Range Expressions 1143
Sequence Expressions 1143
Asynchronous Workflows 1144
Pattern Matching 1146
Active Patterns 1149
Exceptions 1154
Units of Measure 1157
Lazy Computations 1159
Quotations 116°
Working with Database Queries 1161
A Larger Application in F# 1163
The Ast Module 1164
The Language Module 1164
The Evaluator Module 1166
The FunctionPlotter Module H67
Running the Function Plotter 1170
Other .NET Languages 1170
IronRuby 1170
IronPython 1170
Summary
INDEX 1173