Tải bản đầy đủ

Professional visual studio 2013

www.it-ebooks.info


www.it-ebooks.info

badvert.indd 1053

13-02-2014 12:43:15


Professional Visual Studio® 2013
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xliii

➤Part IIntegrated 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 IIGetting 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 IIIDigging 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 IVRich 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

www.it-ebooks.info

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 ViData
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 ViiApplication 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 ViiiConfiguration and Resources
Chapter 37 Configuration Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 701
Chapter 38 Connection Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 719
Chapter 39 Resource Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 729

➤➤Part ixDebugging
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

www.it-ebooks.info

ffirs.indd 2

15-02-2014 14:20:33


➤➤Part xBuild 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 XICustomizing 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

www.it-ebooks.info

ffirs.indd 3

15-02-2014 14:20:33


www.it-ebooks.info

ffirs.indd 4

15-02-2014 14:20:33


Professional

Visual Studio® 2013

www.it-ebooks.info

ffirs.indd 5

15-02-2014 14:20:33


www.it-ebooks.info

ffirs.indd 6

15-02-2014 14:20:33


Professional

Visual Studio® 2013
Bruce Johnson

www.it-ebooks.info

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 http://www.wiley.com/go/permissions.
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 specifically disclaim all warranties, including without limitation warranties of fitness 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 potential 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 standard 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 registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, 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 mentioned in this book.

www.it-ebooks.info

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.

www.it-ebooks.info

ffirs.indd 9

15-02-2014 14:20:34


www.it-ebooks.info

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 first 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 Certified 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 (http://blogs.objectsharp.com/
author/bruce.aspx) has decreased recently, the activity on his Twitter account (http://www.twitter
.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.

www.it-ebooks.info

ffirs.indd 11

15-02-2014 14:20:34


www.it-ebooks.info

ffirs.indd 12

15-02-2014 14:20:34


Credits

Acquisitions Editor

Business Manager

Mary James

Amy Knies

Project Editor

Vice President and Executive
Group Publisher

Kelly Talbot

Richard Swadley
Technical Editor

Andrew Moore

Associate Publisher

Jim Minatel
Production Editor

Daniel Scribner

Project Coordinator, Cover

Todd Klemme
Copy Editor

Charlotte Kughen

Proofreader

Louise Watson, Word One
Editorial Manager

Mary Beth Wakefield

Indexer

Johnna Dinse
Freelancer Editorial Manager

Rosemarie Graham

Cover Designer

Wiley
Associate Director of Marketing

David Mayhew

Cover Image

©philsajonesen/iStockphoto.com
Marketing Manager

Ashley Zurcher

www.it-ebooks.info

ffirs.indd 13

15-02-2014 14:20:34


www.it-ebooks.info

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 something 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 fixed 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.

www.it-ebooks.info

ffirs.indd 15

15-02-2014 14:20:35


www.it-ebooks.info

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
Running Visual Studio 2013
Is Visual Studio Really Cloud Enabled?

The Visual Studio IDE

3
4
5

7

Developing, Building, Debugging, and Deploying
Your First Application

9

Summary13
Chapter 2: The Solution Explorer, Toolbox,
and Properties

The Solution Explorer

15

15

Previewing Files
Common Tasks

17
18

The Toolbox

23

Arranging Components
Adding Components

26
26

Properties27
Extending the Properties Window

29

Summary32
Chapter 3: Options and Customizations

The Start Page

33

33

Customizing the Start Page

Window Layout

34

34

Viewing Windows and Toolbars
35
Navigating Open Items
36
Docking37

The Editor Space

39

Fonts and Colors
Visual Guides
Full-Screen Mode

40
41
42
www.it-ebooks.info

ftoc.indd 17

13-02-2014 12:34:12


CONTENTS

Tracking Changes

43

Other Options

43

Keyboard Shortcuts
Quick Launch
Projects and Solutions
Build and Run
VB Options

43
45
45
46
47

Importing and Exporting Settings
Synchronized Settings

47
49

Summary50
Chapter 4: The Visual Studio Workspace

The Code Editor

51

51

The Code Editor Window Layout
51
Regions52
Outlining53
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
Enhanced Scrollbar
Navigate To

61
62
64

The Command Window
The Immediate Window
The Class View
The Error List
The Object Browser
The Code Definition Window
The Call Hierarchy Window
The Document Outline Tool Window
HTML Outlining
Control Outlining

65
66
67
68
68
69
70
71
71
71

Reorganizing Tool Windows
73
Summary74

xviii

www.it-ebooks.info

ftoc.indd 18

13-02-2014 12:34:12


CONTENTS

Chapter 5: Find and Replace and Help

Quick Find/Replace

75

75

Quick Find
Quick Replace
Find Options
Find and Replace Options

76
77
77
78

Find/Replace in Files

78

Find in Files
Find Dialog Options
Regular Expressions
Results Window
Replace in Files

78
79
80
81
82

Accessing Help

82

Navigating and Searching the Help System
Configuring the Help System

84
84

Summary85
Part II: Getting Started
Chapter 6: Solutions, Projects,
and Items

Solution Structure
Solution File Format
Solution Properties

89

89
91
92

Common Properties
Configuration Properties

92
93

Project Types
Project Files Format
Project Properties

95
97
97

Application98
Compile (Visual Basic Only)
101
Build (C# and F# Only)
102
Build Events (C# and F# Only)
103
Debug104
References (Visual Basic Only)
105
Resources106
Services107
Settings107
Reference Paths (C# and F# Only)
108
Signing109

xix

www.it-ebooks.info

ftoc.indd 19

13-02-2014 12:34:12


CONTENTS

My Extensions (Visual Basic Only)
109
Security110
Publish111
Code Analysis
112

Web Application Project Properties

112

Web113
Silverlight Applications
113
Package/Publish Web
114
Package/Publish SQL
115

Web Site Projects
115
Summary116
Chapter 7: IntelliSense and Bookmarks

IntelliSense Explained

117

117

General IntelliSense
IntelliSense and C++
Completing Words and Phrases
Parameter Information
Quick Info

JavaScript IntelliSense

118
119
119
123
124

124

The JavaScript IntelliSense Context
Referencing Another JavaScript File

XAML IntelliSense
IntelliSense Options

125
125

126
127

General Options
Statement Completion
C#-Specific Options

127
128
129

Extended IntelliSense

129

Code Snippets
XML Comments
Adding Your Own IntelliSense

129
130
130

Bookmarks and the Bookmark Window
130
Summary132
Chapter 8: Code Snippets and Refactoring

Code Snippets Revealed
Storing Code Blocks in the Toolbox
Code Snippets
Using Snippets in C#
Using Snippets in VB
Surround With Snippet

133

133
134
134
135
136
137

xx

www.it-ebooks.info

ftoc.indd 20

13-02-2014 12:34:12


CONTENTS

Code Snippets Manager
Creating Snippets
Reviewing Existing Snippets
Using Snippets in XAML
Distributing Code Snippets

138
139
139
142
143

Accessing Refactoring Support
Refactoring Actions

144
144

Extract Method
144
Encapsulate Field
145
Extract Interface
146
Reorder Parameters
147
147
Remove Parameters
Rename148
Generate Method Stub
149
Organize Usings
149

Summary150
Chapter 9: Server Explorer

Server Connections

151

151

Event Logs
152
Management Classes
154
Management Events
156
Message Queues
158
Performance Counters
160
Services163

Data Connections
164
SharePoint Connections
164
Summary165
Chapter 10: Modeling with the Class Designer

Creating a Class Diagram
The Design Surface
The Toolbox

167

167
168
169

Entities169
Connectors170

The Class Details
170
The Properties Window
171
Layout172
Exporting Diagrams
172
Code Generation and Refactoring
173

xxi

www.it-ebooks.info

ftoc.indd 21

13-02-2014 12:34:12


CONTENTS

Drag-and-Drop Code Generation
IntelliSense Code Generation
Refactoring with the Class Designer

173
175
175

Summary176
Part III: Digging Deeper
Chapter 11: Unit Testing

Your First Test Case

179

179

Identifying Tests Using Attributes
Additional Test Attributes
Unit Tests and Code Lens

Asserting the Facts

184
185
187

188

The Assert Class
The StringAssert Class
The CollectionAssert Class
The ExpectedException Attribute

Initializing and Cleaning Up
TestInitialize and TestCleanup
ClassInitialize and ClassCleanup
AssemblyInitialize and AssemblyCleanup

Testing Context

188
189
189
189

191
191
191
191

192

Data192
Writing Test Output
194

Advanced Unit Testing

195

Custom Properties
Testing Private Members

195
196

Testing Code Contracts
197
Summary199
Chapter 12: Documentation with XML Comments

Inline Commenting
XML Comments

201

201
202

Adding XML Comments
XML Comment Tags

Using XML Comments

202
203

215

IntelliSense Information

216

Generating Documentation with GhostDoc
216
Compiling Documentation with Sandcastle
218
Task List Comments
220
Summary222
xxii

www.it-ebooks.info

ftoc.indd 22

13-02-2014 12:34:12


CONTENTS

Chapter 13: Code Consistency Tools

Source Control

223

223

Selecting a Source Control Repository
Accessing Source Control

Coding Standards

224
225

228

Code Analysis with FxCop
Code Contracts

228
231

Summary233
Chapter 14: Code Generation with T4

235

Creating a T4 Template
T4 Building Blocks

235
238

Expression Blocks
Statement Blocks
Class Feature Blocks

239
239
241

How T4 Works
T4 Directives

242
244

Template Directive
Output Directive
Assembly Directive
Import Directive
Include Directive

244
245
245
245
246

Troubleshooting247
Design-Time Errors
Compiling Transformation Errors
Executing Transformation Errors
Generated Code Errors

Generating Code Assets
Runtime Text Templates

247
247
248
248

248
252

Using Runtime Text Templates
Differences between Runtime Text Templates and
Standard T4 Templates

253
255

Tips and Tricks
256
Summary257
Chapter 15: Project and Item Templates

259

Creating Templates

259

Item Template
Project Template
Template Structure

259
263
264

xxiii

www.it-ebooks.info

ftoc.indd 23

13-02-2014 12:34:13


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay

×