Discover millions of ebooks, audiobooks, and so much more with a free trial

From $11.99/month after trial. Cancel anytime.

Professional Visual Studio 2017
Professional Visual Studio 2017
Professional Visual Studio 2017
Ebook1,547 pages12 hours

Professional Visual Studio 2017

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Skip the basics and delve right into Visual Studio 2017 advanced features and tools

Professional Visual Studio 2017 is the industry-favorite guide to getting the most out of Microsoft's primary programming technology. From touring the new UI to exploiting advanced functionality, this book is designed to help professional developers become more productive. A unique IDE-centric approach provides a clear path through the typical workflow while exploring the nooks and crannies that can make your job easier. Visual Studio 2017 includes a host of features aimed at improving developer productivity and UI, and this book covers them all with clear explanation, new figures, and expert insight. Whether you're new to VS or just upgrading, this all-inclusive guide is an essential resource to keep within arm's reach.

Visual Studio 2017 fixes the crucial issues that kept professionals from adopting VS 2015, and includes new features and tools that streamline the developer's job. This book provides the straightforward answers you need so you can get up to speed quickly and get back to work.

  • Master the core functionality of Visual Studio 2017
  • Dig into the tools that make writing code easier
  • Tailor the environment to your workflow, not the other way around
  • Work your way through configuration, debugging, building, deployment, customizing, and more

Microsoft is changing their release cadence—it's only been about two years since the last release—so developers need to quickly get a handle on new tools and features if they hope to remain productive. The 2017 release is designed specifically to help you get more done, in less time, with greater accuracy and attention to detail. If you're ready to get acquainted, Professional Visual Studio 2017 is your ideal guide.

LanguageEnglish
PublisherWiley
Release dateOct 18, 2017
ISBN9781119404590
Professional Visual Studio 2017

Read more from Bruce Johnson

Related to Professional Visual Studio 2017

Related ebooks

Programming For You

View More

Related articles

Reviews for Professional Visual Studio 2017

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Professional Visual Studio 2017 - Bruce Johnson

    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.

    WARNING

    Boxes like this one hold important, not-to-be forgotten information that is directly relevant to the surrounding text.

    NOTE

    Notes, tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.

    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.

    NOTE

    Because many books have similar titles, you may find it easiest to search by ISBN; this book's ISBN is 978-1-119-40458-3.

    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.

    NOTE

    a complete book list including links to errata is also available at www.wrox.com/misc-pages/booklist.shtml.

    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:

    Go to p2p.wrox.com and click the Register link.

    Read the terms of use and click Agree.

    Complete the required information to join as well as any optional information you wish to provide and click Submit.

    You will receive an e-mail with information describing how to verify your account and complete the joining process.

    NOTE

    You can read messages in the forums without joining P2P but in order to post your own messages, you must join.

    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

    CHAPTER 1: A Quick Tour

    CHAPTER 2: The Solution Explorer, Toolbox, and Properties

    CHAPTER 3: Options and Customizations

    CHAPTER 4: The Visual Studio Workspace

    CHAPTER 5: Find and Replace and Help

    1

    A Quick Tour

    WHAT’S IN THIS CHAPTER?

    What’s in This Chapter?

    Installing and getting started with Visual Studio 2017

    Creating and running your first application

    Debugging and deploying an application

    Ever since software has been developed, there has been a need for tools to help write, compile, debug, and deploy applications. Microsoft Visual Studio 2017 is the next iteration in the continual evolution of a best-of-breed integrated development environment (IDE).

    This chapter introduces the Visual Studio 2017 user experience and shows you how to work with the various menus, toolbars, and windows. It serves as a quick tour of the IDE, and as such it doesn’t go into detail about what settings can be changed or how to go about customizing the layout because these topics are explored in the following chapters.

    GETTING STARTED

    Recent versions of Visual Studio have seen incremental improvements in the installation experience. However, Visual Studio 2017 has pretty much completely revamped the installation options and workflow. It has been designed to not only get you up and running quickly, but also to easily select only those options you need to have installed. This section walks you through the installation process and getting started with the IDE.

    Installing Visual Studio 2017

    The installer for Visual Studio 2017 is what Microsoft calls a low-impact installer. The idea arose as Microsoft compared the footprint used by Visual Studio 2015 with the kinds of experiences that users were not only requesting, but also using. As surprising as it might seem, not every developer needs to have Visual Studio support for Windows Forms, ASP.NET, WPF, Universal Apps, and C++ out of the box.

    Visual Studio 2015 and earlier versions were optimized so that pressing F5 to run a program would work out of the box. It wasn’t expected that you would need to install any other components in order to get the large majority of .NET applications running. While this was a definite plus regarding ease of use, it made for a large (some might say bloated) footprint for Visual Studio.

    In Visual Studio 2017, the installation process takes a different point of view. Instead of automatically installing everything, you get to pick and choose the different components that you want to install. Yes, you had a little bit of that in the past, but now the number of options that you have is greatly increased. However, more options doesn’t necessarily mean a better installation experience. In fact, it’s probably the opposite, as you try to figure out which of a hundred different options you need to install to work on your project. To address that challenge, the Visual Studio 2017 installer uses the concept of workloads.

    When you launch the Visual Studio 2017 installation process (an application of only a couple of megabytes in size), you’ll see the dialog in Figure 1-1 appear relatively quickly. Naturally, this is after you have read (in great detail, of course) and accepted the licensing information and privacy statements.

    Snapshot of Visual Studio 2017 installastion dialog box.

    FIGURE 1-1

    This is the main hub for the installer and the location where the desired components are specified. There are two modes for identifying the components. In Figure 1-1, you are looking at the workloads. The workloads have been divided into five different categories. To include a workload in the installation, simply click on it, showing a blue checkbox in the top right corner. You can add any number of the workloads as part of the installation. The available workloads are:

    Universal Windows Platform development: Used if you are creating applications for the Universal Windows Platform, regardless of your language of choice.

    .NET desktop development: Allows you to create applications, using either WPF or Windows Forms. This is also where you find the Console application template.

    Desktop development with C++: Used to build classic Windows-based applications. This option is appropriate if you expect to be using Visual C++, the Active Template Library (ATL), or Microsoft Foundation Classes (MFC).

    ASP.NET and web development: Adds the components used to build web applications, including ASP.NET, ASP.NET Core, and plain old HTML/Javascript/CSS.

    Azure development: Includes the Azure SDK, tools, and project templates that allow you to create Azure-based cloud applications.

    Python development: Includes support for cookiecutter, Python 3, and tools that are used to interact with Azure. And, optionally, you can include other distributions of Python, such as Anaconda.

    Node.js development: One of the new tools supported by Visual Studio 2017, this workload includes the components that allow you to create network applications using the Node.js platform.

    Data storage and processing: Some recent additions to the Azure platform include Azure Data Lake, Hadoop, and Azure ML (Machine Learning). This workload includes the templates and tools to develop applications for this platform, along with the Azure SQL Server database.

    Data science and analytical applications: Brings together three languages that are also found in other workloads: R, Python, and F#. These tools can be used to build a wide variety of analytics-based applications.

    Office/SharePoint development: Used to create a wide variety of Office and SharePoint applications, including Office add-ins, SharePoint solutions, and Visual Studio Tools for Office (VSTO) add-ins.

    Mobile development with .NET: One of the three technologies that Visual Studio 2017 supports for mobile development, this workload allows you to create iOS, Android, or Windows applications using Xamarin.

    Mobile development with JavaScript: Similar concept to the previous entry, but instead of using Xamarin, your applications are developed using Tools for Apache Cordova and JavaScript.

    Mobile development with C++: And the last of the three mobile development environments allows you to create iOS, Android, and Windows applications using C++.

    Game development with Unity: Unity is a broadly used and very flexible cross-platform game development environment. This workload allows you to create 2D and 3D games using the Unity framework.

    Game development with C++: Supports the creation of games using C++ along with libraries like DirectX, Unreal, or Cocos2d.

    Visual Studio extension development: Lets you create add-ons and extensions for use in Visual Studio. Included in this are code analyzers and tool windows that take advantage of the Roslyn compiler functionality.

    Linux development with C++: Windows 10 includes an option to install an Ubuntu-based Linux Bash shell. This workload includes the set of tools and libraries that allow you to create applications that run in Linux using Visual Studio.

    .NET Core cross-platform development: .NET Core is a popular approach to cross-platform development. This workload allows you to create .NET Core applications, including web applications.

    WORKLOADS USED IN THIS BOOK

    In order to work through the examples in the book, there are a number of workloads that need to be installed. Specifically:

    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

    The second mode for choosing components is more granular. If you select the Individual Components link at the top of the installation screen, the list of components shown in Figure 1-2 appears. From here you can select any or all of the individual components that you want to install on your machine.

    Snapshot of list of components at the top of the installation screen.

    FIGURE 1-2

    NOTE

    To see the relationship between the workloads and the more granular components that are included, simply select a workload. A list of the components that are included appears in the pane on the right side of the dialog.

    The third installation option you have for Visual Studio is to include one or more of the supported language packs. Clicking on the Language Packs link displays the list of language packs that are available (see Figure 1-3).

    Snapshot of Language Packs link displaying the list of language packs.

    FIGURE 1-3

    Once you have selected your components (either individually or as part of a workload), choose the installation location and click on Install. Now comes the longer part of the process. You’ll see the progress dialog, an example of which is shown in Figure 1-4. Depending on which components you already have installed on your computer, you might be prompted to restart your computer midway through or at the end of the installation process. When all the components have been successfully installed, the original dialog changes slightly (as shown in Figure 1-5). This final dialog is also the starting point for adding features to Visual Studio in the future.

    Snapshot of progress dialog.

    FIGURE 1-4

    Snapshot of original dialog.

    FIGURE 1-5

    Running Visual Studio 2017

    The first time you run Visual Studio 2017, you might be given the opportunity to sign in. If you had already signed in from within Visual Studio 2015, you won’t be prompted to log in. Your credentials are remembered between the versions. However, if you’re new to Visual Studio, then you’ll be asked to provide a Microsoft Live account.

    This behavior is part of an effort to cloud-enable Visual Studio—to connect Visual Studio settings and functionality to assets that are available across the Internet. There is no requirement for you to log in. The login page includes a Not Now, Maybe Later link. Clicking on that link skips a number of steps and lets you get to Visual Studio quickly. But there are some decent benefits that can be derived by signing in.

    Is Visual Studio Really Cloud Enabled?

    The quick answer is Yes. A more accurate answer is Yes, if you want it to be. Part of the research work behind creating this feature involved Microsoft gaining an understanding of how developers identified themselves to various online functions. In general, most developers have two or more Microsoft accounts that they use when they develop. There is a primary identity, which typically maps to the credentials used by the person while working. Then there are additional identities used to access external functions, such as Team Foundation Server, or to publish apps onto the various Microsoft stores.

    To mimic how developers work with these multiple online identities, Microsoft introduces a hierarchical relationship between these identities within Visual Studio. When you sign in, the account you specify is the primary identity for the Visual Studio IDE. It should, in theory, represent you (that is you, the person). Every place you sign into Visual Studio with the same credentials, your preferred settings will follow you. This includes customizations like themes and keyboard bindings. And a change on one device will automatically flow to the other devices you are signed into.

    To handle the secondary credentials, Visual Studio 2017 contains a secure credential store. This allows the connections that you have made to external services to be remembered and used without the need to provide authentication each time. Naturally, you can manually sign out from a particular connection and the credentials will be removed.

    As part of the cloud enabling, you see your name (assuming that you logged in) in the top right of the IDE. If you click on the drop-down arrow (shown in Figure 1-6), you can see an Account Settings link. Clicking on that link takes you to a dialog (see Figure 1-7) in which you can manage the details of your account, including associating Visual Studio with different accounts.

    Snapshot of top right of the IDE.

    FIGURE 1-6

    Snapshot of a dialog.

    FIGURE 1-7

    Along with providing a mechanism for editing the basic contact information for the profile, the dialog includes a list of the Microsoft Live accounts that have been remembered on your current machine.

    THE VISUAL STUDIO IDE

    The first time you launch Visual Studio 2017 , you will most likely see a dialog indicating that Visual Studio is configuring the development environment. When this process is complete, Visual Studio 2017 opens, ready for you to start working, as shown in Figure 1-8.

    Snapshot of Visual Studio 2017 interface.

    FIGURE 1-8

    You’ll see the Start page in the center of the screen. The bulk of the page contains links to the most common functions that you’re likely to perform. For example, there is a list of Recent projects, along with links that allow you to open existing projects or create a new project. And in the latter case, the most commonly used templates are prominently on display. The previous version of the Start page included a news feed of interest to developers, and that feed is still present in Visual Studio 2017. And in the top left, there is also a Get Started section with links to information that is useful to new users of Visual Studio.

    Before you launch into building your first application, you must take a step back to look at the components that make up the Visual Studio 2017 IDE. Menus and toolbars are positioned along the top of the environment, and a selection of subwindows, or panes, appears on the left, right, and bottom of the main window area. In the center is the main editor space. Whenever you open a code file, an XML document, a form, or some other file, it appears in this space for editing. With each file you open, a tab is created so that you can easily switch between opened files.

    On either side of the editor space is a set of tool windows. These areas provide additional contextual information and functionality. For the general developer settings, the default layout includes the Solution Explorer and Properties on the right, and the Server Explorer and Toolbox on the left. The tool windows on the left are in their collapsed, or unpinned, state. If you click a tool window’s title, it expands; it collapses again when it no longer has focus or you move the cursor to another area of the screen. When a tool window is expanded, you see a series of three icons at the top right of the window, similar to those shown in the top right corner of Figure 1-9.

    Snapshot of tool window expanded, to show a series of three icons at the top right of the window, similar to those shown in the top right corner.

    FIGURE 1-9

    If you want the tool window to remain in its expanded, or pinned, state, you can click the middle icon, which looks like a pin. The pin rotates 90 degrees to indicate that the window is now pinned. Clicking the third icon, the X, closes the window. If later you want to reopen this or another tool window, you can select it from the View menu.

    NOTE

    Some tool windows are not accessible via the View menu; for example, those having to do with debugging, such as threads and watch windows. In most cases these windows are available via an alternative menu item; for the debugging windows, it is the Debug menu.

    When the first icon, the down arrow, is clicked, a context menu opens. Each item in this list represents a different way to arrange the tool window. As you would imagine, the Float option enables the tool window to be placed anywhere on the screen, independent of the main IDE window. This is useful if you have multiple screens because you can move the various tool windows onto the additional screen, allowing the editor space to use the maximum screen real estate. Selecting the Dock as Tabbed Document option makes the tool window into an additional tab in the editor space. In Chapter 4, The Visual Studio Workspace, you’ll learn how to effectively manage the workspace by docking tool windows.

    Developing, Building, Debugging, and Deploying Your First Application

    Now that you have seen an overview of the Visual Studio 2017 IDE, this section walks you through creating a simple application that demonstrates working with some of these components. This is, of course, the mandatory Hello World sample that every developer needs to know, and it can be done in either Visual Basic .NET, or C#, depending on what you feel more comfortable with.

    Start by selecting File ➪ New ➪ Project. This opens the New Project dialog, as shown in Figure 1-10. There is a tree on the left side of the dialog for grouping templates based on language and technology. And there is also a search box in the top-right corner. The right pane of this dialog displays additional information about the project template you have selected. Lastly, you can select the version of the .NET Framework that the application will target using the drop-down at the top of the dialog. Select WPF Application from the Templates area (this item exists under the root Visual Basic and Visual C# nodes, or under the subnode Windows) and set the Name to GettingStarted before selecting OK. This creates a new WPF application project, which includes a single startup window and is contained within a Chapter 1 solution, as shown in the Solution Explorer window of Figure 1-11. This startup window has automatically opened in the visual designer, giving you an approximate graphical representation of what the window will look like when you run the application. The Properties tool window is collapsed and sits on the right side of the windows.

    Snapshot of New Project dialog.

    FIGURE 1-10

    Snapshot of Solution Explorer window.

    FIGURE 1-11

    Click the collapsed Toolbox window, which appears on the left side of the screen. This causes the Toolbox to expand. Then click on the pin icon, which keeps the tool window open. To add controls to the window in the GettingStarted project, select the appropriate items from the Toolbox and drag them onto the form. Alternatively, you can double-click the item, and Visual Studio automatically adds them to the window.

    Add a button and textbox to the form so that the layout looks similar to the one shown in Figure 1-12. Select the textbox, and select the Properties tool window. (You can press F4 to automatically open the Properties tool window.) Change the name of the control (found at the top of the Properties tool window) to txtSayHello. Repeat for the Button control, naming it btnSayHello and setting the Content property to Say Hello!

    Illustration of adding button and textbox to the form.

    FIGURE 1-12

    You can quickly locate a property by typing its name into the search field located beneath the Name field. In Figure 1-12Conten has been entered to reduce the list of Properties so that it’s easier to locate the Content property.

    After you add controls to the window, the tab is updated with an asterisk (*) after the text to indicate that there are unsaved changes to that particular item. If you attempt to close this item while changes are pending, you are asked if you want to save the changes. When you build the application, any unsaved files are automatically saved as part of the build process.

    NOTE

    One thing to be aware of is that some files, such as the solution file, are modified when you make changes within Visual Studio 2017 without your being given any indication that they have changed. If you try to exit the application or close the solution, you are still prompted to save these changes.

    Deselect all controls (you can click an empty spot on the screen to do this), and then double-click the button. This not only opens the code editor with the code-behind file for this form, it also creates and wires up an event handler for the click event on the button. Figure 1-13 shows the code window after a single line has been added to echo the message to the user.

    Illustration of code window after a single line added to echo the message to the user.

    FIGURE 1-13

    Before you build and execute your application, place the cursor somewhere on the line containing MessageBox.Show and press F9. This sets a breakpoint; when you run the application by pressing F5 and then click the Say Hello! button, the execution halts at this line. Figure 1-14 illustrates this breakpoint being reached. The data tip, which appears when the mouse hovers over the line, shows the contents of the txtSayHello.Text property.

    Illustration of a breaking point reached in the code.

    FIGURE 1-14

    The layout of Visual Studio in Figure 1-14 is significantly different from the previous screenshots because a number of tool windows are visible in the lower half of the screen, and command bars are visible at the top. Also, the status bar at the bottom of the IDE is orange, as opposed to the blue that appears when in design mode. When you stop running or debugging your application, Visual Studio returns to the previous layout. Visual Studio 2017 maintains two separate layouts: design time and run time. Menus, toolbars, and various windows have default layouts for when you edit a project, whereas a different setup is defined for when a project is executed and debugged. You can modify each of these layouts to suit your own style, and Visual Studio 2017 remembers them.

    You need to deploy your application. Whether you build a rich client application using Windows Forms or WPF, or a web application using IIS, Azure, Node.js, or any of a number of other technologies, Visual Studio 2017 has the capability to publish your application. Double-click the Properties node in Solution Explorer, and select the Publish node to display the options for publishing your application, as shown in Figure 1-15. In Figure 1-15, the publishing folder has been set to a local path (by default, the path is relative to the directory in which the project is found), but you can specify a network folder, an Internet Information Services (IIS) folder, or an FTP site instead. After you specify where you want to publish to, clicking Publish Now publishes your application to that location.

    Illustration of publishing folder.

    FIGURE 1-15

    SUMMARY

    You’ve seen how the various components of Visual Studio 2017 work together to build an application. The following list outlines the typical process of creating a solution:

    Use the File menu to create a solution.

    Use the Solution Explorer to locate the window that needs editing, and double-click the item to show it in the main workspace area.

    Drag the necessary components onto the window from the Toolbox.

    Select the window and each component in turn, and edit the properties in the Properties window.

    Double-click the window or a control to access the code behind the component’s graphical interface.

    Use the main workspace area to write code and design the graphical interface, switching between the two via the tabs at the top of the area.

    Use the toolbars to start the program.

    If errors occur, review them in the Error List and Output windows.

    Save the project using either toolbar or menu commands, and exit Visual Studio 2017.

    In subsequent chapters, you’ll learn how to customize the IDE to more closely fit your own working style. You’ll also see how Visual Studio 2017 takes a lot of the guesswork out of the application development process and a number of best practices for working with Visual Studio 2017 that you can reuse as a developer.

    2

    The Solution Explorer, Toolbox, and Properties

    WHAT’S IN THIS CHAPTER?

    Arranging files with the Solution Explorer

    Adding projects, items, and references to your solution

    Working with the Properties tool window

    Including your own properties in the Properties tool window

    WROX.COM CODE DOWNLOADS FOR THIS CHAPTER

    The wrox.com code downloads for this chapter can be found at www.wrox.com by searching for this book’s ISBN number (978-1-119-40458-3). The code and any related support files are located in their own folder for this chapter.

    In Chapter 1, A Quick Tour, you briefly saw and interacted with a number of the components that make up the Visual Studio 2017 IDE. Now you get an opportunity to work with three of the most commonly used tool windows: the Solution Explorer, the Toolbox, and Properties.

    Throughout this and other chapters you see references to keyboard shortcuts, such as Ctrl+S. In these cases, we assume the use of the general development settings, as shown in Chapter 1. Other profiles may have different key combinations. And, as you will see in upcoming chapters, you can use the Quick Launch area to get to commands regardless of the development settings that you use.

    THE SOLUTION EXPLORER

    Most of the time, when you create or open an application, or for that matter just a single file, Visual Studio 2017 uses the concept of a solution to tie everything together. Visual Studio 2017 introduces the concept of a Folder view, which is discussed further later in this chapter. For most situations (and definitely for most existing projects), the solution is the root element of a project.

    Typically, a solution is made up of one or more projects, each of which can have multiple items associated with it. In the past these items were typically just files, but increasingly projects are made up of items that may consist of multiple files, or in some cases no files at all. Chapter 6, Solutions, Projects, and Items, goes into more detail about projects, the structure of solutions, and how items are related.

    The Solution Explorer tool window (Ctrl+Alt+L) provides a convenient visual representation of the solution, projects, and items, as shown in Figure 2-1. In this figure you can see three projects presented in a tree: a C# Windows Presentation Foundation (WPF) application, a C# Windows Communication Foundation (WCF) service library, and a Visual Basic (VB) class library.

    Illustration of Solution Explorer tool window.

    FIGURE 2-1

    Each project has an icon associated with it that typically indicates the type of project and the language it is written in. There are some exceptions to this rule: Some projects, such as SQL Server or Modeling projects, aren’t tied to a specific language.

    One node is particularly noticeable because the font is boldfaced. This indicates that this project is the startup project — in other words, the project that is launched when you select Debug ➪ Start Debugging or press F5. To change the startup project, right-click the project you want to nominate and select Set as StartUp Project. You can also nominate multiple projects as startup projects via the Solution Properties dialog, which you can reach by selecting Properties from the right-click menu of the Solution node.

    NOTE

    With certain environment settings, the Solution node is not visible when only a single project exists. A problem with this setting is that it becomes difficult to access the Solution Properties window. To get the Solution node to appear, you can either add another project to the solution or check the Always Show Solution item from the Projects and Solutions node in the Options dialog, accessible via Tools Options.

    The toolbar across the top of the Solution Explorer gives access to a number of different functions related to the solution, from the ability to collapse all the files in the tree to creating a new instance of the Solution Explorer. For example, the Show All Files icon (see Figure 2-2) expands the solution listing to display the additional files and folders.

    Illustration of Show All Files icon.

    FIGURE 2-2

    In this expanded view you can see all the files and folders contained under the project structure. Unfortunately, if the file system changes, the Solution Explorer does not automatically update to reflect these changes. Use the Refresh button (two buttons to the left of the Show All Files button) to make sure you see the current list of files and folders.

    The Solution Explorer toolbar is contextually aware, with different buttons displayed depending on the type of node selected. This is shown in Figure 2-3. The image on the left shows the toolbar when a .XAML file is selected. It includes a View Code icon (the fourth from the right). However, when a different file is selected, as illustrated in the image on the right, the View Code icon is missing.

    Illustration of Solution Explorer toolbar.

    FIGURE 2-3

    There is another, relatively unusual mechanism for navigating through the projects and files in a solution. To the left of each item in the tree is an icon, which when clicked shows a different context menu. Included in this menu is an option called Scope to This. When the Scope to This option is clicked, the contents of the Solution Explorer change so that the selected node in the solution becomes the top level of the tree view. Figure 2-4 shows the view when Scope to This has been clicked for the GettingStarted project.

    Illustration of the view when Scope to This has been clicked for the GettingStarted project.

    FIGURE 2-4

    Along with navigating down the solution using the Scope to This option, the Solution Explorer also allows for moving backward and forward through the navigation. At the top left of the Solution Explorer’s toolbar, there is a left arrow that you can use to navigate up the hierarchy. So if that arrow were clicked, the full solution would be displayed, as shown in Figure 2-2. And there is also a right-facing arrow that, when clicked, navigates forward into the scoped view.

    Visual Studio 2017 includes the ability to open a folder instead of opening a solution. While it is available for any project type, it would seem to be most relevant to web applications where there is no need to tie the elements of the project together beyond existing within a single project. While a similar idea (Web Sites) was included in earlier versions of Visual Studio (and is still available in Visual Studio 2017), increased support for build tools like Grunt and Bower has brought the feature to the forefront.

    First, it is possible at any time to switch between the Solution view and the Folder view for a solution. Figure 2-5 illustrates the difference between the two views. The fourth button from the left in both views is used to toggle between views.

    Illustration of switch between the Solution view and the Folder view.

    FIGURE 2-5

    The Solution view is on the left and looks familiar to regular users of past versions of Visual Studio. The Folder view is on the right. What previously had been a project is now a folder (assuming that is how you organized your solution in the file system). Files that had been grouped together in the Solution view (like App.xaml and App.xaml.cs) now appear as individual files in the Folder view. Artifacts like the .sln file are now visible in the solution explorer. And the context menu has changed significantly, with the Folder view having far fewer choices.

    If you have been using Visual Studio for a while, it’s natural to ask what purpose the Folder View serves. For most projects, the answer is not much. However, as odd as it might sound, the folder structure that is displayed in the traditional view of the Solution Explorer is actually a virtual one. That is, the files in the file system don’t need to follow the folder structure shown in the Solution Explorer. Your files can be placed in a single folder in the file system but show up within a folder structure in your project.

    For most projects, this is not a big deal. Actually, it’s irrelevant to the running of your application. The build process is able to figure out where the files are and compile them into the appropriate assemblies, and your application runs. However, for certain kinds of projects (and web applications, including .NET Core, are the leading culprits), the physical folder structure matters. The Folder View allows you to quickly and easily see how the files lay out physically.

    The rest of this chapter concentrates on the options available in the Solution view.

    In the Solution view in Visual Studio 2017, expanding any source code node reveals the properties and methods for a given class. And the context menu for the node contains options targeting the selected item. When you right-click a class (not the code file, but the actual class), the context menu includes Base Types, Derived Types, and Is Used By options. These options change the scope of the Solution Explorer to the base class, the derived classes, and the classes used by the selected class, respectively.

    As you continue navigating into the properties and methods, the context menu includes Calls, Is Called By, and Is Used By. These options scope the Solution Explorer to the classes that call this class, classes that are called by this class, and classes that are used by this class, respectively.

    Previewing Files

    One of the more interesting features of Visual Studio 2017 is the file preview capability of Solution Explorer. One of the buttons at the top of the Solution Explorer is Preview Selected Items (shown in Figure 2-6). When it has been selected, as you navigate through the files in the Solution Explorer (to navigate, the file must be selected either with the mouse or by using the cursor), the file appears on the Preview tab (Figure 2-6).

    Snapshot of Preview Selected Items button.

    FIGURE 2-6

    At this moment, the file has not been modified but is simply open to look at. You are free to navigate through the file as you would any other file. However, when you navigate to another file in the Solution Explorer, the Preview tab is replaced with the new file. In other words, it is no longer required to have a proliferation of tabs to view the contents of various files in your solution.

    When you decide to stop previewing the file, it automatically moves to the tabs on the left side of your editor window. You make the choice to stop previewing either by editing the file directly (by typing, for example) or by selecting the Open option from the drop-down list on the right of the Preview tab.

    Common Tasks

    In addition to providing a convenient way to manage projects and items, the Solution Explorer has a dynamic context menu that gives you quick access to some of the most common tasks, such as building the solution or individual projects, accessing the build configuration manager, and opening files. Figure 2-7 shows how the context menu varies depending on which item is selected in the Solution Explorer.

    Snapshot of context menu.

    FIGURE 2-7

    The first items in the left and center menus relate to building either the entire solution or the selected project. In most cases, selecting Build is the most efficient option, because it only builds projects where one or more of the contained files have changed. However, in some cases you may need to force a Rebuild, which builds all dependent projects regardless of their states. If you just want to remove all the additional files that are created during the build process, you can invoke Clean. This option can be useful if you want to package your solution to email it to someone — you wouldn’t want to include all the temporary or output files that are created by the build.

    For most items in the Solution Explorer, the first section of the context menu is similar to the right menu in Figure 2-7. The default Open and Open With items allow you to determine how the item will be opened. This is of particular use when you work with files that have a custom editor. A common example is a RESX file. By default, Visual Studio 2017 opens this file type using the built-in resource editor, but this prevents you from making certain changes and doesn’t support all data types you might want to include. (Chapter 56, Resource Files, in the online archive goes into how you can use your own data types in resource files.) By using the Open With menu item, you can use the XML Editor instead.

    NOTE

    The context menu for the Solution, Project, and Folder nodes contains the Open Folder in File Explorer item. This enables you to open File Explorer (Windows Explorer) quickly to the location of the selected item, saving you the hassle of having to navigate to where your solution is located, and then find the appropriate subfolder.

    Adding Projects and Items

    The most common activities carried out in the Solution Explorer are the addition, removal, and renaming of projects and items. To add a new project to an existing solution, select Add ➪ New Project from the context menu off the Solution node. This invokes the dialog in Figure 2-8. Project templates can be sorted and searched from this dialog, and the pane on the right side displays information about the selected project, such as the type of project and its description. As well, the light-weight installer means that a template you’re looking for might be in a workload that has not already been installed. To relaunch the installer and add a desired workload, there is an Open Visual Studio Installer link that will start that process for you. Chapter 11, Project and Item Templates, covers creating your own Project and Item templates, including setting these properties.

    Illustration of a dialog box.

    FIGURE 2-8

    In the Installed templates hierarchy on the left side of the Add New Project dialog, the templates are primarily arranged by language (Azure Data Lake being the exception) and then by technology. There are also nodes for Recent templates and Online templates. The Online templates can be sorted and searched in the same way as your Installed templates.

    The other thing you will notice in this dialog is the ability to select different framework versions through a dropdown at the middle top of the form. Visual Studio 2017 does not require a migration for most project types. So if you have existing projects that you don’t want to have to migrate forward to a more recent version of the .NET Framework, you can still immediately take advantage of the current features in Visual Studio 2017. The framework selection is also included in the search criteria, limiting the list of available project templates to those that are compatible with the selected .NET Framework version.

    NOTE

    When you open your existing Visual Studio 2012, 2013, or 2015 solutions or projects in Visual Studio 2017, they will not necessarily go through the upgrade wizard. (See Chapter 34, Upgrading with Visual Studio 2017, for more information.) To be precise, the act of opening a project in Visual Studio 2017 might cause modifications to the project, but it will still be able to be opened in earlier versions of Visual Studio (in some cases, even as far back as Visual Studio 2010). This is both important enough to warrant additional comment. What this means for developers is that they might be able to use Visual Studio 2017 to modify legacy projects (thus getting the benefits of using the latest version of the IDE). At the same time, projects that have been opened in Visual Studio 2017 will still open in Visual Studio 2015, 2013, or 2012. For projects that are from versions earlier than Visual Studio 2012, the upgrade wizard will be triggered. These matters are discussed further in Chapter 34.

    One of the worst and most poorly understood features in Visual Studio is the concept of a Web Site project. This is distinct from a Web Application project, which can be added via the aforementioned Add New Project dialog. To add a Web Site project, you need to select Add ➪ New Web Site from the context menu off the Solution node. This displays a dialog similar to the one shown in Figure 2-9, where you can select the type of web project to be created. In most cases, this simply determines the type of default item that is to be created in the project.

    Image of a dialog box.

    FIGURE 2-9

    NOTE

    It is important to note that some of the web projects listed in Figure 2-9 can also be created by going through the ASP.NET Web Application options in the Add New Project dialog. However, understand that they will not generate the same results because significant differences exist between Web Site projects (created via the Add New Web Site dialog) and Web Application projects (created via the Add New Project dialog). The differences between these project types are covered in detail in Chapter 16, ASP.NET Web Forms.

    When you have a project or two in your solution, you need to start adding items. You do this via the Add context menu item off the project node in the Solution Explorer. The first submenu, New Item, launches the Add New Item dialog, as shown in Figure 2-10.

    Snapshot of Add New Item dialog.

    FIGURE 2-10

    In addition to listing only those item templates that are relevant to the project you have selected, the Add New Item dialog enables you to search the installed templates, as well as go online to look for templates made available by third parties.

    Returning to the Add context menu, you will notice a number of predefined shortcuts such as User Control and Class. The shortcuts that appear depend on the type of project to which the item is being added. These do little more than bypass the stage of locating the appropriate template within the Add New Item dialog. With just a few exceptions, the Add New Item dialog is still displayed because you need to assign a name to the item being created.

    It is important to make the distinction that you are adding items rather than files to the project. Though a lot of the templates contain only a single file, some, like the Window or User Control, add multiple files to your project.

    Adding References

    Each new software development technology that is released promises better reuse, but few can actually deliver on this promise. One way that Visual Studio 2017 supports reusable components is via the references for a project. If you expand the References node for any project, you can observe a number of .NET Framework libraries, such as System and System.Core, which need to be included by the compiler to successfully build the project. Essentially, a reference enables the compiler to resolve type, property, field, and method names back to the assembly where they are defined. If you want to reuse a class from a third-party library, or even your own .NET assembly from another project, you need to add a reference to it via the Add Reference context menu item on the project node of the Solution Explorer.

    When you launch the Reference Manager dialog, as shown in Figure 2-11, Visual Studio 2017 interrogates the local computer, the Global Assembly Cache, and your solution to present a list of known libraries that can be referenced. This includes both .NET and COM references that are separated into different lists, as well as projects and recently used references.

    Snapshot of Reference Manager dialog.

    FIGURE 2-11

    As in other project-based development environments going back as far as the first versions of VB, you can

    Enjoying the preview?
    Page 1 of 1