Tải bản đầy đủ (.pdf) (1,102 trang)

professional visual studio 2013

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (43.34 MB, 1,102 trang )

badvert.indd 1053 13-02-2014 12:43:15
PROFESSIONAL VISUAL STUDIO
®
2013
INTRODUCTION xliii
➤ PART I INTEGRATED DEVELOPMENT ENVIRONMENT
CHAPTER 1 A Quick Tour 3
CHAPTER 2 The Solution Explorer, Toolbox, and Properties 15
CHAPTER 3 Options and Customizations 33
CHAPTER 4 The Visual Studio Workspace 51
CHAPTER 5 Find and Replace and Help 75
➤ PART II GETTING STARTED
CHAPTER 6 Solutions, Projects, and Items 89
CHAPTER 7 IntelliSense and Bookmarks 117
CHAPTER 8 Code Snippets and Refactoring 133
CHAPTER 9 Server Explorer 151
CHAPTER 10 Modeling with the Class Designer 167
➤ PART III DIGGING DEEPER
CHAPTER 11 Unit Testing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
CHAPTER 12 Documentation with XML Comments 201
CHAPTER 13 Code Consistency Tools 223
CHAPTER 14 Code Generation with T4 235
CHAPTER 15 Project and Item Templates 259
CHAPTER 16 Language-Specific Features 277
➤ PART IV RICH CLIENT APPLICATIONS
CHAPTER 17 Windows Forms Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
CHAPTER 18 Windows Presentation Foundation (WPF) 307
CHAPTER 19 Office Business Applications 333
CHAPTER 20 Windows Store Applications 349
Continues


ffirs.indd 1 15-02-2014 14:20:33
➤ PART V WEB APPLICATIONS
CHAPTER 21 ASP.NET Web Forms 363
CHAPTER 22 ASP.NET MVC 395
CHAPTER 23 Silverlight 425
CHAPTER 24 Dynamic Data 439
CHAPTER 25 SharePoint 461
CHAPTER 26 Windows Azure 481
➤ PART VI DATA
CHAPTER 27 Visual Database Tools 499
CHAPTER 28 DataSets and DataBinding 507
CHAPTER 29 Language Integrated Queries (LINQ) 533
CHAPTER 30 The ADO.NET Entity Framework 559
CHAPTER 31 Reporting 581
➤ PART VII APPLICATION SERVICES
CHAPTER 32 Windows Communication Foundation (WCF) 617
CHAPTER 33 Windows Workflow Foundation (WF) 637
CHAPTER 34 Client Application Services 659
CHAPTER 35 Synchronization Services 677
CHAPTER 36 WCF RIA Services 687
➤ PART VIII CONFIGURATION AND RESOURCES
CHAPTER 37 Configuration Files 701
CHAPTER 38 Connection Strings 719
CHAPTER 39 Resource Files 729
➤ PART IX DEBUGGING
CHAPTER 40 Using the Debugging Windows 749
CHAPTER 41 Debugging with Breakpoints 767
CHAPTER 42 DataTips, Debug Proxies, and Visualizers 779
CHAPTER 43 Debugging Web Applications 791
CHAPTER 44 Advanced Debugging Techniques 807

ffirs.indd 2 15-02-2014 14:20:33
➤ PART X BUILD AND DEPLOYMENT
CHAPTER 45 Upgrading with Visual Studio 2013 829
CHAPTER 46 Build Customization 835
CHAPTER 47 Assembly Versioning and Signing 851
CHAPTER 48 Obfuscation, Application Monitoring, and Management 859
CHAPTER 49 Packaging and Deployment 879
CHAPTER 50 Web Application Deployment 893
➤ PART XI CUSTOMIZING AND EXTENDING VISUAL STUDIO
CHAPTER 51 The Automation Model 905
CHAPTER 52 Add-Ins 913
CHAPTER 53 Managed Extensibility Framework (MEF) 927
➤ PART XII VISUAL STUDIO ULTIMATE
CHAPTER 54 Visual Studio Ultimate for Architects 949
CHAPTER 55 Visual Studio Ultimate for Developers 961
CHAPTER 56 Visual Studio Ultimate for Testers 977
CHAPTER 57 Team Foundation Server 991
INDEX 1013
ffirs.indd 3 15-02-2014 14:20:33
ffirs.indd 4 15-02-2014 14:20:33
PROFESSIONAL
Visual Studio
®
2013
ffirs.indd 5 15-02-2014 14:20:33
ffirs.indd 6 15-02-2014 14:20:33
PROFESSIONAL
Visual Studio
®
2013

Bruce Johnson
ffirs.indd 7 15-02-2014 14:20:34
Professional Visual Studio
®
2013
Published by
John Wiley & Sons, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2014 by John Wiley & Sons, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-1-118-83204-2
ISBN: 978-1-118-83206-6 (ebk)
ISBN: 978-1-118-83205-9 (ebk)
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 />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 specically disclaim all warranties, including without limita-
tion warranties of tness 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 poten-

tial 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 publishes in a variety of print and electronic formats and by print-on-demand. Some material included with stan-
dard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such
as a CD or DVD that is not included in the version you purchased, you may download this material at http://book
support.wiley.com. For more information about Wiley products, visit www.wiley.com.
Library of Congress Control Number: 2014930419
Trademarks: Wiley, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are trademarks or regis-
tered trademarks of John Wiley & Sons, Inc. and/or its afliates, in the United States and other countries, and may not be
used without written permission. Visual Studio is a registered trademark of Microsoft Corporation. All other trademarks
are the property of their respective owners. John Wiley & Sons, Inc., is not associated with any product or vendor men-
tioned in this book.
ffirs.indd 8 15-02-2014 14:20:34
I’d like to thank my wife, Ali, and my four children,
Kyle, Cameron, Gillian, and Curtis, for their love and
support. Throughout the process of writing this book,
they were well-behaved and completely respectful of my
time. Okay, that’s not true at all. But they are my loves
and my life would be much less rich without them.
ffirs.indd 9 15-02-2014 14:20:34
ffirs.indd 10 15-02-2014 14:20:34
ABOUT THE AUTHOR
BRUCE JOHNSON is a partner at ObjectSharp Consulting and a 30-year veteran of the computer industry.
The rst third of his career was spent doing “real work,” otherwise known as coding in the UNIX world.
But for 20 years, he has been working on projects that are at the leading edge of Windows technology, from
C++ through Visual Basic to C#, and from thick client applications to websites to services.
As well as having fun with building systems, Bruce has spoken hundreds of times at conferences and user

groups throughout North America. He has been a Microsoft Certied Trainer (MCT) for the past four years
and he is a co-president of the Metro Toronto .NET User Group. He has also written columns and articles
for numerous magazines. While the quantity of the posts on his blog (
/>author/bruce.aspx
) has decreased recently, the activity on his Twitter account (tter
.com/lacanuck
) has shown a corresponding increase. For all of this activity (or, perhaps, in spite of it),
Bruce has been privileged to be recognized as a Microsoft MVP for the past eight years.
ffirs.indd 11 15-02-2014 14:20:34
ffirs.indd 12 15-02-2014 14:20:34
CREDITS
ACQUISITIONS EDITOR
Mary James
PROJECT EDITOR
Kelly Talbot
TECHNICAL EDITOR
Andrew Moore
PRODUCTION EDITOR
Daniel Scribner
COPY EDITOR
Charlotte Kughen
EDITORIAL MANAGER
Mary Beth Wakefield
FREELANCER EDITORIAL MANAGER
Rosemarie Graham
ASSOCIATE DIRECTOR OF MARKETING
David Mayhew
MARKETING MANAGER
Ashley Zurcher
BUSINESS MANAGER

Amy Knies
VICE PRESIDENT AND EXECUTIVE
GROUP PUBLISHER
Richard Swadley
ASSOCIATE PUBLISHER
Jim Minatel
PROJECT COORDINATOR, COVER
Todd Klemme
PROOFREADER
Louise Watson, Word One
INDEXER
Johnna Dinse
COVER DESIGNER
Wiley
COVER IMAGE
©philsajonesen/iStockphoto.com
ffirs.indd 13 15-02-2014 14:20:34
ffirs.indd 14 15-02-2014 14:20:34
ACKNOWLEDGMENTS
TO THE OUTSIDE, it might look like the writing of a book is an individual effort. Having gone through
this act of creation a number of times, I can tell you that nothing is further from the truth. Yes, there is a
lot of effort on the part of the author (and the feeling of joy you get as you hand in your last rewrite is quite
palpable). But I can also tell you that without the rarely acknowledged efforts of the others involved in the
editorial process, the book would never have made it to completion. And if you, as the reader, take some-
thing useful from this book, odds are that my editor, my technical reviewer, and the project editor are the
reason why.
I would especially like to thank everyone at Wrox who has helped me through this process. In particular,
thanks go out to Kelly Talbot, whose patience and attention to detail are quite impressive. Thanks also go
to Andrew Moore, who did a great job making sure that the technical details of the book were accurate.
Finally, thanks to Charlotte Kughen, who had the unenviable chore of ensuring that I wasn’t writing in the

passive voice and xed it when I stopped writing so well. The efforts of all of these individuals are what
make the book possible and, hopefully, a success. Thanks also to Mary James, who was kind enough to take
a chance on my ability to write.
ffirs.indd 15 15-02-2014 14:20:35
ffirs.indd 16 15-02-2014 14:20:35
Contents
INTRODUCTION xliii
Part I: Integrated develoPment envIronment
ChaPter 1: a QuICk tour 3
Getting Started 3
Installing Visual Studio 2013 3
Running Visual Studio 2013 4
Is Visual Studio Really Cloud Enabled? 5
The Visual Studio IDE 7
Developing, Building, Debugging, and Deploying
Your First Application 9
Summary 13
ChaPter 2: the solutIon exPlorer, toolbox,
and ProPertIes 15
The Solution Explorer 15
Previewing Files 17
Common Tasks 18
The Toolbox 23
Arranging Components 26
Adding Components 26
Properties 27
Extending the Properties Window 29
Summary 32
ChaPter 3: oPtIons and CustomIzatIons 33
The Start Page 33

Customizing the Start Page 34
Window Layout 34
Viewing Windows and Toolbars 35
Navigating Open Items 36
Docking 37
The Editor Space 39
Fonts and Colors 40
Visual Guides 41
Full-Screen Mode 42
ftoc.indd 17 13-02-2014 12:34:12
xviii
CONTENTS
Tracking Changes 43
Other Options 43
Keyboard Shortcuts 43
Quick Launch 45
Projects and Solutions 45
Build and Run 46
VB Options 47
Importing and Exporting Settings 47
Synchronized Settings 49
Summary 50
ChaPter 4: the vIsual studIo WorksPaCe 51
The Code Editor 51
The Code Editor Window Layout 51
Regions 52
Outlining 53
Code Formatting 53
Navigating Forward/Backward 54
Additional Code Editor Features 54

Split View 56
Tear Away (Floating) Code Windows 56
Duplicating Solution Explorer 58
Creating Tab Groups 58
Advanced Functionality 59
Code Navigation 60
Peek Definition 61
Enhanced Scrollbar 62
Navigate To 64
The Command Window 65
The Immediate Window 66
The Class View 67
The Error List 68
The Object Browser 68
The Code Definition Window 69
The Call Hierarchy Window 70
The Document Outline Tool Window 71
HTML Outlining 71
Control Outlining 71
Reorganizing Tool Windows 73
Summary 74
ftoc.indd 18 13-02-2014 12:34:12
xix
CONTENTS
ChaPter 5: FInd and rePlaCe and helP 75
Quick Find/Replace 75
Quick Find 76
Quick Replace 77
Find Options 77
Find and Replace Options 78

Find/Replace in Files 78
Find in Files 78
Find Dialog Options 79
Regular Expressions 80
Results Window 81
Replace in Files 82
Accessing Help 82
Navigating and Searching the Help System 84
Configuring the Help System 84
Summary 85
Part II: gettIng started
ChaPter 6: solutIons, ProjeCts,
and Items 89
Solution Structure 89
Solution File Format 91
Solution Properties 92
Common Properties 92
Configuration Properties 93
Project Types 95
Project Files Format 97
Project Properties 97
Application 98
Compile (Visual Basic Only) 101
Build (C# and F# Only) 102
Build Events (C# and F# Only) 103
Debug 104
References (Visual Basic Only) 105
Resources 106
Services 107
Settings 107

Reference Paths (C# and F# Only) 108
Signing 109
ftoc.indd 19 13-02-2014 12:34:12
xx
CONTENTS
My Extensions (Visual Basic Only) 109
Security 110
Publish 111
Code Analysis 112
Web Application Project Properties 112
Web 113
Silverlight Applications 113
Package/Publish Web 114
Package/Publish SQL 115
Web Site Projects 115
Summary 116
ChaPter 7: IntellIsense and bookmarks 117
IntelliSense Explained 117
General IntelliSense 118
IntelliSense and C++ 119
Completing Words and Phrases 119
Parameter Information 123
Quick Info 124
JavaScript IntelliSense 124
The JavaScript IntelliSense Context 125
Referencing Another JavaScript File 125
XAML IntelliSense 126
IntelliSense Options 127
General Options 127
Statement Completion 128

C#-Specific Options 129
Extended IntelliSense 129
Code Snippets 129
XML Comments 130
Adding Your Own IntelliSense 130
Bookmarks and the Bookmark Window 130
Summary 132
ChaPter 8: Code snIPPets and reFaCtorIng 133
Code Snippets Revealed 133
Storing Code Blocks in the Toolbox 134
Code Snippets 134
Using Snippets in C# 135
Using Snippets in VB 136
Surround With Snippet 137
ftoc.indd 20 13-02-2014 12:34:12
xxi
CONTENTS
Code Snippets Manager 138
Creating Snippets 139
Reviewing Existing Snippets 139
Using Snippets in XAML 142
Distributing Code Snippets 143
Accessing Refactoring Support 144
Refactoring Actions 144
Extract Method 144
Encapsulate Field 145
Extract Interface 146
Reorder Parameters 147
Remove Parameters 147
Rename 148

Generate Method Stub 149
Organize Usings 149
Summary 150
ChaPter 9: server exPlorer 151
Server Connections 151
Event Logs 152
Management Classes 154
Management Events 156
Message Queues 158
Performance Counters 160
Services 163
Data Connections 164
SharePoint Connections 164
Summary 165
ChaPter 10: modelIng WIth the Class desIgner 167
Creating a Class Diagram 167
The Design Surface 168
The Toolbox 169
Entities 169
Connectors 170
The Class Details 170
The Properties Window 171
Layout 172
Exporting Diagrams 172
Code Generation and Refactoring 173
ftoc.indd 21 13-02-2014 12:34:12
xxii
CONTENTS
Drag-and-Drop Code Generation 173
IntelliSense Code Generation 175

Refactoring with the Class Designer 175
Summary 176
Part III: dIggIng deePer
ChaPter 11: unIt testIng 179
Your First Test Case 179
Identifying Tests Using Attributes 184
Additional Test Attributes 185
Unit Tests and Code Lens 187
Asserting the Facts 188
The Assert Class 188
The StringAssert Class 189
The CollectionAssert Class 189
The ExpectedException Attribute 189
Initializing and Cleaning Up 191
TestInitialize and TestCleanup 191
ClassInitialize and ClassCleanup 191
AssemblyInitialize and AssemblyCleanup 191
Testing Context 192
Data 192
Writing Test Output 194
Advanced Unit Testing 195
Custom Properties 195
Testing Private Members 196
Testing Code Contracts 197
Summary 199
ChaPter 12: doCumentatIon WIth xml Comments 201
Inline Commenting 201
XML Comments 202
Adding XML Comments 202
XML Comment Tags 203

Using XML Comments 215
IntelliSense Information 216
Generating Documentation with GhostDoc 216
Compiling Documentation with Sandcastle 218
Task List Comments 220
Summary 222
ftoc.indd 22 13-02-2014 12:34:12
xxiii
CONTENTS
ChaPter 13: Code ConsIstenCy tools 223
Source Control 223
Selecting a Source Control Repository 224
Accessing Source Control 225
Coding Standards 228
Code Analysis with FxCop 228
Code Contracts 231
Summary 233
ChaPter 14: Code generatIon WIth t4 235
Creating a T4 Template 235
T4 Building Blocks 238
Expression Blocks 239
Statement Blocks 239
Class Feature Blocks 241
How T4 Works 242
T4 Directives 244
Template Directive 244
Output Directive 245
Assembly Directive 245
Import Directive 245
Include Directive 246

Troubleshooting 247
Design-Time Errors 247
Compiling Transformation Errors 247
Executing Transformation Errors 248
Generated Code Errors 248
Generating Code Assets 248
Runtime Text Templates 252
Using Runtime Text Templates 253
Differences between Runtime Text Templates and
Standard T4 Templates 255
Tips and Tricks 256
Summary 257
ChaPter 15: ProjeCt and Item temPlates 259
Creating Templates 259
Item Template 259
Project Template 263
Template Structure 264
ftoc.indd 23 13-02-2014 12:34:13

×