Cover Page

PROFESSIONAL
Visual Studio® 2017

 

 

 

Bruce Johnson

 

 

 

 

 

 

Wiley Logo

I'd like to thank my four children, Kyle, Cameron, Gillian, and Curtis, for their love and support. All the kids are teenagers now, so they were quite happy to leave me alone to write as much as I needed. And this time around, some of them can drive. As a result, leaving me alone was even less demanding on them than it has been for past books. They are my loves and my life would be much less rich without them.

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 rich client applications to web applications and APIs, with a sprinkling of database and front-end development thrown in for good measure.

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) and the co-president of the Metro Toronto .NET User Group. He has also written columns and articles for numerous magazines. For all of this activity, Bruce was also a Microsoft MVP for more than ten years. At the moment, he's already working on the outline for his next book. Because why not?

ABOUT THE TECHNICAL EDITOR

JOHN MUELLER is a freelance author and technical editor. He has writing in his blood, having produced 104 books and more than 600 articles to date. The topics range from networking to artificial intelligence to database management to heads-down programming and beyond. Some of his current works include a book about machine learning, a couple of Python books, and a book about MATLAB. He has also written AWS for Admins for Dummies, which provides administrators with a great place to start with AWS, and AWS for Developers for Dummies, the counterpart for developers. His technical editing skills have helped more than 70 authors refine the content of their manuscripts. John has always been interested in development and has written about a wide variety of languages, including a highly successful C++ book. Be sure to read John's blog at http://blog.johnmuellerbooks.com. You can reach John on the Internet at John@JohnMuellerBooks.com.

CREDITS

  • SENIOR ACQUISITIONS EDITOR
    Kenyon Brown
  • PROJECT EDITOR
    Kelly Talbot
  • TECHNICAL EDITOR
    John Mueller
  • PRODUCTION EDITOR
    Athiyappan Lalith Kumar
  • COPY EDITOR
    Kelly Talbot Editing Services
  • MANAGER OF CONTENT DEVELOPMENT AND ASSEMBLY
    Mary Beth Wakefield
  • PRODUCTION MANAGER
    Kathleen Wisor
  • MARKETING MANAGER
    Christie Hilbrich
  • EXECUTIVE EDITOR
    Jim Minatel
  • PROJECT COORDINATOR, COVER
    Brent Savage
  • PROOFREADER
    Nancy Bell
  • INDEXER
    Nancy Guenther
  • COVER DESIGNER
    Wiley
  • COVER IMAGE
    ©frantic00/Shutterstock

ACKNOWLEDGMENTS

TO THE OUTSIDE, it might look like the writing of a book is an individual effort. It's not. Not even close. There is no way that this book could have come to fruition without the efforts and assistance of a number of people. The fact that the book is clear, accurate, and useful is because of the contributions of my editor, my technical editor, my copy editor, and the proofreader. And I haven't even gotten to those who are responsible for the production of the final copies. I'm incredibly grateful for everyone's help and have enjoyed working with these very talented people. It's makes the process a lot more enjoyable.

I would especially like to thank everyone at Wrox who has helped me through this process. In particular, thanks go out to Kelly Talbot. This is, if I'm not mistaken, the third or fourth book on which I have worked with Kelly. As always, his attention to detail has prevented a very large number of mistakes. But, more than that, he is not only patient, but diligent in ensuring that I meet my deadlines. Thanks also go to John Mueller, who not only made sure that the technical mistakes I made in my first draft were cleaned up before publication, but also provided some great suggestions that helped me clarify my writing. Finally, thanks to Nancy Bell, who had to slog through what I wrote and convert it to grammatically correct prose. The efforts of all of these individuals are what make the book possible and, hopefully, a success.

INTRODUCTION

AS A TOOL FOR DEVELOPERS, Visual Studio stands head and shoulders about its competition. The team responsible for developing Visual Studio has always put the productivity of people who code for a living at the top of their priority list. This version continues this tradition. Visual Studio always incorporates the latest advances in Microsoft's premier programming languages (Visual Basic and C#), as well as adding little tidbits of functionality that are a boon to coders. But at a higher level, Visual Studio 2017 embraces open-source, mobile development, and cloud computing in a variety of ways. Azure is continually introducing new features and products and Visual Studio 2017 integrates seamlessly with them. While, in theory, it is possible to create any .NET application using tools as simple as Notepad and a command-line window, the typical developer would never think to do so. Visual Studio 2017, as was the case with its predecessors, includes a host of improvements and features that are aimed at making the life of a developer easier.

Visual Studio 2017 is an enormous product no matter which way you look at it. It can be intimidating to newcomers and difficult for even experienced .NET developers to find what they need. And that's where this book comes in. Professional Visual Studio 2017 looks at every major aspect of this developer tool, showing you how to harness each feature and offering advice about how best to utilize the various components effectively. It shows you the building blocks that make up Visual Studio 2017, breaking the user interface down into manageable chunks for you to understand. It then expands on each of these components with additional details about exactly how they work, both in isolation and in conjunction with other parts of Visual Studio 2017, along with tools that are not included in the out-of-the-box product, to make your development efforts even more efficient.

WHO THIS BOOK IS FOR

Professional Visual Studio 2017 is for developers who are new to Visual Studio as well as those programmers who have some experience but want to learn about features they may have previously overlooked.

Even if you are familiar with the way previous versions of Visual Studio worked, you may want to at least skim over Part I. These chapters deal with the basic constructs that make up the user interface. The biggest changes to the building blocks are in the installation process. It is more granular, meaning that you install only what you need and if you don't install a component initially, the installer is only a click or two away. But there are some little additions in functionality, so while you can get by without Part I, some of the changes in Visual Studio 2017 can make you a more efficient developer. And, after all, that's what you're looking to get out of this book.

If you're just starting out, you'll greatly benefit from the first part, where basic concepts are explained and you're introduced to the user interface and how to customize it to suit your own style.

WHAT THIS BOOK COVERS

Microsoft Visual Studio 2017 is arguably the most advanced integrated development environment (IDE) available for programmers today. It is based on a long history of programming languages and interfaces and has been influenced by many different variations on the theme of development environments.

Visual Studio 2017 does not represent a major departure from recent versions. Still, regardless of the type of application you're creating, there are tweaks that have been made—some small, some less so (.NET Core, for example). Familiarity with the changes helps you perform your job better. For this reason, as well as to help newcomers to Visual Studio, this book covers the breadth of the product. Along the way, you will become more familiar and comfortable with the interface.

Visual Studio 2017 comes in several versions: Community, Professional, and Enterprise. The majority of this book deals with the Professional Edition of Visual Studio 2017, but some chapters utilize features found only in the Enterprise edition. If you haven't used this edition before, read through Chapters 38 and 39 for an overview of the features it offers over and above the Professional Edition.

HOW THIS BOOK IS STRUCTURED

This book is divided into 11 parts:

  • Integrated Development Environment: This book's first five chapters are dedicated to familiarizing you with the core aspects of Visual Studio 2017, from the IDE structure and layout to the various options and settings you can change to make the user interface synchronize with your own way of doing things.
  • Getting Started: In this part, you learn how to take control of your projects and how to organize them in ways that work with your own style.
  • Digging Deeper: Though the many graphical components of Visual Studio that make a programmer's job easier are discussed in many places throughout this book, you often need help when you're in the process of actually writing code. This part deals with features that support the coding of applications such as IntelliSense, code refactoring, and creating and running unit tests.
  • Desktop Applications: Rich client applications have seen quite a transition within the .NET Framework, moving from Windows Forms applications to Windows Presentation Foundation (WPF) to Universal Windows Applications. Each of these gets its own chapter in this part.
  • Web Applications: Web applications have seen even more transitions than Desktop applications. And just like Desktop applications, each of the three different development styles (ASP.NET Web Forms, ASP.NET MVC, and .NET Core) gets its own chapter. And a couple of new kids on the block, Node.js and Python, are also included in this part.
  • Mobile Applications: There are two different styles of mobile application development that are supported with Visual Studio 2017. Through Xamarin, it's possible to create mobile apps using familiar .NET components. And by using Apache Cordova (formerly PhoneGap), you can target mobile devices using HTML, CSS, and JavaScript.
  • Cloud Services: Visual Studio 2017 supports the cloud in a wide variety of ways. The chapter on Windows Azure looks at how some of the newer features of Azure are integrated into Visual Studio. And the use of synchronization services as a data storage platform is examined, along with how to create apps for SharePoint.
  • Data: A large proportion of applications use some form of data storage. Visual Studio 2017 and the .NET Framework include strong support for working with databases and other data sources. This part examines how to use the Visual Database Tools, and ADO.NET Entity Framework to build applications that work with data. It also shows you how you how to take advantage of a couple of new functions within Azure to support data warehouse construction and data analytics.
  • Debugging: Application debugging is one of the more challenging tasks developers have to tackle, but correct use of the Visual Studio 2017 debugging features will help you analyze the state of the application and determine the cause of any bugs. This part examines the debugging support provided by the IDE.
  • Build and Deployment: In addition to discussing how to build your solutions effectively and get applications into the hands of your end users, this part also deals with the process of upgrading your projects from previous versions.
  • Visual Studio Editions: The final part of the book examines the additional features only available in the Enterprise version of Visual Studio 2017. In addition, you'll also learn how Visual Studio Team Services provides an essential tool for managing software projects.

Though this breakdown of the Visual Studio feature set provides the most logical and easily understood set of topics, you may need to look for specific functions that will aid you in a particular activity. To address this need, references to appropriate chapters are provided whenever a feature is covered in more detail elsewhere in the book.

As Visual Studio has grown over the years, the size of earlier versions of this book had grown to the point where it was unwieldy. And there were even more features with Visual Studio 2017. So to avoid a book whose size would be pushing 2,000 pages, we took a number of the chapters from earlier editions of Visual Studio and put them into an online archive. These chapters contain features that have not been changed or enhanced in Visual Studio 2017. As such, the instructions found therein will apply, in general, if you're trying to use them in Visual Studio 2017. You can find the online archive on www.wrox.com.

WHAT YOU NEED TO USE THIS BOOK

To use this book effectively, you'll need only one additional item — Microsoft Visual Studio 2017 Professional Edition. With this software installed and the information found in this book, you'll be able to get a handle on how to use Visual Studio 2017 effectively in a very short period of time. In order to be able to follow along with all of the examples in the book, you'll want to be sure to install the following workloads during your Visual Studio 2017 installation (as discussed in Chapter 1):

  • Universal Windows Platform
  • .NET desktop development
  • ASP.NET and web development
  • Azure development
  • Node.js development
  • Data storage and processing
  • Data science and analytical applications
  • Mobile development with .NET
  • Mobile development with Javascript
  • .NET code cross-platform development

This book assumes that you are familiar with the traditional programming model, and it uses both the C# and Visual Basic (VB) languages to illustrate features within Visual Studio 2017. In addition, it is assumed that you can understand the code listings without an explanation of basic programming concepts in either language. If you're new to programming and want to learn Visual Basic, please take a look at Beginning Visual Basic 2015 by Bryan Newsome. Similarly, if you are after a great book on C#, track down Beginning C# 6 Programming with Visual Studio 2015 by Benjamin Perkins, Jacob Vibe Hammer, and Jon D. Reid.

Some chapters discuss additional products and tools that work in conjunction with Visual Studio. The following are all available to download either on a trial basis or for free:

  • Code Snippet Editor: This is a third-party tool developed for creating code snippets in VB. The Snippet Editor tool is discussed in Chapter 8.
  • SQL Server 2016: The installation of Visual Studio 2017 includes an install of SQL Server 2016 Express, enabling you to build applications that use database files. However, for more comprehensive enterprise solutions, you can use a full SQL Server 2016 instead.
  • Visual Studio 2017 Enterprise Edition: This more advanced version of Visual Studio introduces tools for other parts of the development process such as testing and design. They are discussed in Chapters 38-39.
  • Team Foundation Server or Team Foundation Service: The server product (or the cloud-based equivalent) that provides application lifecycle management throughout Visual Studio 2017. This is covered in Chapter 40.
  • Windows 7, Windows 8, or Windows 10: Visual Studio 2015 is compatible with Windows 7 SP1, and 8.1, and, of course, Windows 10. It can produce applications that run on Windows XP, Windows Vista, Windows 7, Windows 8, and Windows 10.

CONVENTIONS

To help you get the most from the text and keep track of what's happening, we've used a number of conventions throughout the book.

As for styles in the text:

  • We highlight new terms and important words when we introduce them.
  • We show URLs and code within the text like so: persistence.properties.
  • We present code in the following way:
We use a monofont type for code examples.
We use bold to emphasize code that is particularly important in the present context or to show changes from a previous code snippet.

SOURCE CODE

As you work through the examples in this book, you may choose either to type in all the code manually or to use the source code files that accompany the book. All the source code used in this book is available for download at www.wrox.com.

You can also search for the book at www.wrox.com by ISBN (the ISBN for this book is 978-1-119-40458-3) to find the code. And a complete list of code downloads for all current Wrox books is available at www.wrox.com/dynamic/books/download.aspx.

Alternately, you can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.

Most of the code on www.wrox.com is compressed in a .ZIP, .RAR archive, or similar archive format appropriate to the platform. Once you download the code, just decompress it with your favorite compression tool.

ERRATA

We make every effort to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error in one of our books, like a spelling mistake or faulty piece of code, we would be very grateful for your feedback. By sending in errata you may save another reader hours of frustration and at the same time you will be helping us provide even higher quality information.

To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or one of the title lists. Then, on the Book Search Results page, click the Errata link. On this page you can view all errata that has been submitted for this book and posted by Wrox editors.

If you don't spot “your” error on the Errata page, click the Errata Form link and complete the form to send us the error you have found. We'll check the information and, if appropriate, post a message to the book's errata page and fix the problem in subsequent editions of the book.

P2P.WROX.COM

For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a web-based system for you to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to email you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums.

At http://p2p.wrox.com you will find a number of different forums that will help you, not only as you read this book, but also as you develop your own applications. To join the forums, just follow these steps:

  1. Go to p2p.wrox.com and click the Register link.
  2. Read the terms of use and click Agree.
  3. Complete the required information to join as well as any optional information you wish to provide and click Submit.
  4. You will receive an e-mail with information describing how to verify your account and complete the joining process.

Once you join, you can post new messages and respond to messages other users post. You can read messages at any time on the Web. If you would like to have new messages from a particular forum emailed to you, click the Subscribe to this Forum icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works as well as many common questions specific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.

PART I
Integrated Development Environment