Visual Studio 2019 Tricks and Techniques

By Paul Schroeder , Aaron Cure
    Advance your knowledge in tech with a Packt subscription

  • Instant online access to over 7,500+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. Chapter 1: Flavors of Visual Studio

About this book

Visual Studio 2019 (VS 2019) and Visual Studio Code (VS Code) are powerful professional development tools that help you to develop applications for any platform with ease. Whether you want to create web, mobile, or desktop applications, Microsoft Visual Studio is your one-stop solution. This book demonstrates some of the most sophisticated capabilities of the tooling and shows you how to use the integrated development environment (IDE) more efficiently to be more productive.

You’ll begin by gradually building on concepts, starting with the basics. The introductory chapters cover shortcuts, snippets, and numerous optimization tricks, along with debugging techniques, source control integration, and other important IDE features that will help you make your time more productive. With that groundwork in place, more advanced concepts such as the inner workings of project and item templates are covered. You will also learn how to write quality, secure code more efficiently as well as discover how certain Visual Studio features work 'under the hood'.

By the end of this Visual Studio book, you’ll have learned how to write more secure code faster than ever using your knowledge of the extensions and processes that make developing successful solutions more enjoyable and repeatable.

Publication date:
January 2021
Publisher
Packt
Pages
386
ISBN
9781800203525

 

Chapter 1: Flavors of Visual Studio

Microsoft Visual Studio is an Integrated Development Environment (IDE) from Microsoft. Over its more than twenty-year history, it has been used by developers to develop all kinds of computer programs, web applications, web APIs, and mobile apps. A 2019 survey by Stack Overflow found Visual Studio and its cousin, Visual Studio Code (VS Code), to be two of the most popular development environments among all survey respondents (see https://insights.stackoverflow.com/survey/2019):

Figure 1.1 – Stack Overflow 2019 survey

Figure 1.1 – Stack Overflow 2019 survey

Note on Stack Overflow 2020 survey results

Although Stack Overflow's 2020 survey results were available at the time of writing, they did not seem to include the same specific question on development environments.

Visual Studio provides robust coding and debugging capabilities as well as extensive integration for deployment and source control needs. You can use it to program anything from a desktop business application, to a web site, mobile application, or Unity game.

If you are new to programming or .NET development, it is important to understand that there are several options to consider before starting. This chapter's primary focus is to cover some key factors you should consider when deciding which product "flavor" of Visual Studio is right for you, including the following:

  • Primary operating system (Windows, macOS, or Linux)
  • Target framework (.NET full framework, .NET Core)
  • Team size and budget
  • Application type (Windows, web, mobile, server, or console)
  • Cross-platform portability requirements
  • Chosen programming language (such as C#, VB, Python, Ruby, or NodeJS)

The reason why we must examine the aforementioned points in detail is because Microsoft has combined what are actually multiple, separate, products under a single marketing umbrella. This can make choosing between these products confusing and so we will take a moment to clearly identify each version, differentiate their features, and provide some guidance on which version may be best for your purposes.

 

Technical requirements

The code for this book is available on GitHub at: https://github.com/PacktPublishing/Visual-Studio-2019-Tricks-and-Techniques/tree/main/.

Please check the following link for CiA videos: http://bit.ly/3oxE5QM.

 

Quick reference cheat sheet

With so many options, how does a developer know which version to use? The following is a list of simplified suggestions to help you choose a particular flavor:

  • If you are using a PC and are brand new to software development, start with VS 2019 Community.
  • If you are using a PC as an experienced developer, or have a well-funded company footing the bill, consider the VS 2019 Professional or VS 2019 Enterprise editions.
  • If you're primarily a web developer planning to use NodeJS and TypeScript, try VS Code.
  • If you're developing cross-platform iOS/Android mobile apps, consider using VS for Mac.

    Have you already decided on which version to use?

    If you have already figured out which version of Visual Studio is right for you, then feel free to skip this chapter's content. Alternatively, if you are an experienced developer, skim this material looking for new tidbits, such as GitHub Codespaces.

For those readers that need more information to decide, let's begin digging into the details of the most long-lived product flavor, Visual Studio for Windows.

 

Visual Studio 2019 (Windows)

Let's start with Visual Studio 2019 (VS 2019), a Windows-based IDE (pronounced AYE-dee-ee). Some people will refer to this product as the full version. This version only runs on Windows (not cross-platform), but it does support both .NET "full framework" and .NET Core (cross-platform) project targets. Something all versions of Visual Studio do exceptionally well is work with diverse programming languages (including C, C++, Visual Basic. NET, C#, F#, JavaScript, TypeScript, Python, Ruby, and Node.js).

Different tiers of features are offered, depending on your needs and budget. Current versions of VS 2019 include a free Community edition as well as paid Professional, Enterprise, and Test Professional versions. The Community and Professional editions are nearly identical when it comes to operational features and, for most development tasks, any version of Visual Studio will work.

The Community version is depicted in the screenshot that follows and you will find virtually no difference between its appearance and that of the other versions:

Figure 1.2 – VS 2019 Community – Windows

Figure 1.2 – VS 2019 Community – Windows

Even with multiple options, choosing a Visual Studio edition is much easier today than in the past. Previously, certain project types could only be loaded in one edition or another, and many add-ins would not run in certain editions. Complex licensing issues compounded these problems, making it more difficult to choose.

Today, even the free Community edition is a powerful environment with much to offer. Many of the popular features, such as peeking at definitions, multi-targeting of release targets, and refactoring are supported in all editions.

More succinctly, the major versions of VS 2019 are as follows:

  • Community – Free for students, open source contributors, and individuals
  • Professional – The best choice for small teams
  • Test Professional – An option for dedicated Quality Assurance (QA) roles
  • Enterprise – Offers extra features (mentioned later in this chapter) and works well for teams of any size

In the past, the Community version, originally labeled "Express," was a very limited version that allowed only basic application development but would not allow for particular target types (such as Visual Studio plugins), and would also not allow a number of plugins to run. While some of these limitations seemed minor, they were enough to create negative perceptions of the platform among some developers and sour development community sentiment on the Community version. In recent years, Microsoft has removed many of the original restrictions and enabled so much functionality in this version that the experience is now very similar to the Professional version.

Traditionally, the Professional version was the lowest tier version for "true" developers. Because of the limitations of other versions, this was the only way to do "actual" development. This version tier is (and always has been) a full-featured IDE with all the bells and whistles you would expect in a professional development tool.

A key difference is that VS 2019 Community is free, while the Professional version retails for about $1,199 for the first year's subscription and $799 annually for renewal thereafter. However, there are license restrictions that limit use of Visual Studio Community to teams of less than five developers. Also, it cannot be used by commercial organizations with over $1 million US dollars in annual revenue.

For those whose focus is purely QA, and not development, Test Professional is another option to consider. It provides an integrated testing toolset for QA teams, but does not include an IDE to build applications. Instead, this product flavor focuses on the creation and execution of tests and test suites. It also integrates nicely with Visual Studio Team Foundation Server (VSTFS) and Azure DevOps (ADO).

Finally, the Enterprise version of VS 2019 is available for organizations with more than 25 developers, or those seeking to take advantage of advanced features only available at this highest tier. This level includes advanced functionality such as memory profilers, Snapshot Debugger, Live Unit Testing, architectural layer diagrams, and architecture validation. An overview of some of these capabilities is provided next.

Features of VS 2019 Enterprise edition

The following provides a brief overview of a few features that are specific to the Enterprise version of VS 2019. These items may help you decide whether this is the right flavor of the IDE for your needs:

  • Performance profiling tools: VS 2019 provides a dozen or more profiling tools that can help diagnose different kinds of performance issues. Common metrics you may want to analyze include CPU usage, memory usage, and database performance. Some of these tools require the Enterprise edition, and some do not. Use this link to investigate the specific tools that match your needs: https://docs.microsoft.com/en-us/visualstudio/profiling/profiling-feature-tour?view=vs-2019.
  • Live Unit Testing: While you are coding, Live Unit Testing automatically runs unit tests in the background and shows your code coverage live in Visual Studio. It provides a line-by-line visual indicator of test coverage as well as the status of passing/failing tests. As you modify code, this feature dynamically executes tests and provides immediate notification when changes cause tests to fail.
  • Snapshot Debugger: If you are using Azure Application Insights, the Snapshot Debugger can be used to capture the state of source code and variables from a live, running, application. This can be helpful for troubleshooting exceptions that occur in a production environment. If you do not have the Enterprise edition of Visual Studio, you can view debug snapshots in the online portal, but using the Enterprise edition provides a more robust debugging experience.
  • Live Dependency Validation: Another feature, only available in the Enterprise edition, is Live Dependency Validation. This lets teams validate architectural dependencies to ensure that they respect defined architectural constraints. In complex multi-layer applications, this can help ensure code dependencies flow in the right direction, which is important for maintainability. This can be useful on project teams with junior developers who may not fully understand the design. Detailed coverage of the Live Dependency Validation feature is beyond the scope of this chapter, but this video link provides a basic overview: https://channel9.msdn.com/Events/Visual-Studio/Visual-Studio-2017-Launch/T123.

    Visual Studio Installer

    To use certain features, like Code Map and Live Dependency Validation components, you must run the Visual Studio Installer, select the Individual components tab, and scroll down to the Code tools section. From there, select the Code Map and Live Dependency Validation components, as shown in the following screenshot. When you are ready, click the Modify button:

Figure 1.3 – Visual Studio Installer

Figure 1.3 – Visual Studio Installer

Note

To be accurate, Visual Studio's Community and Professional editions do allow you to open diagrams that were generated using the Enterprise edition, albeit in read-only mode.

Despite their differences, from a functionality standpoint, the look and feel of all the editions are pretty much the same. Menus, tools, and functional controls are all implemented consistently, perform the same functions, and are mostly indistinguishable from one another.

Use the following link to review specific differences between versions: https://visualstudio.microsoft.com/vs/compare/.

In short, whichever version you choose, the experience should be nearly the same. For most development tasks, it makes no difference which version you are running: they all have the basic software development life cycle tools to create, debug, and run web, mobile, console, library, and just about any other project you can devise.

 

Visual Studio 2019 for Mac

If Windows isn't your primary operating system, Microsoft also offers Visual Studio for Mac, which unsurprisingly runs on Apple's macOS operating system. Historically, this product evolved from what was known as Xamarin Studio prior to Microsoft's acquisition of Xamarin in 2016.

Visual Studio 2019 for Mac supports development in C#, F#, Razor, HTML, CSS, JavaScript, TypeScript, XAML, and XML. It also supports ASP.NET Core and .NET Core development, Azure Functions, Azure Connected Services, and the ability to publish to Azure. Like its Windows parallel, the Mac version comes in Community, Professional, and Enterprise versions. It has support for using Docker containers, Unity game programming, and mobile app development using Xamarin and C#:

Figure 1.4 – Visual Studio 2019 – Mac

Figure 1.4 – Visual Studio 2019 – Mac

Note

One notable feature missing from VS 2019 for Mac, VS Code (discussed next), and .NET Core in general, is the ability to create cross-platform desktop applications (such as WPF, Windows Forms, and UWP). While there are several possible alternatives (Electron, Avalonia UI, Uno Platform, and so on), none truly stand out as a native interface like WPF on Windows with Visual Studio.

For convenience, the following figure shows a feature comparison between Visual Studio 2019 for Mac and VS 2019 (Windows). The few differences between these products lie in Mac's lack of support for some types of Windows desktop, Python, and Node.js development:

Figure 1.5 – Visual Studio 2019 for Mac versus VS 2019 (Windows)

Figure 1.5 – Visual Studio 2019 Comparison

Note

The full image is available in Chapter 1, Flavors of Visual Studio at https://static.packt-cdn.com/downloads/9781800203525_ColorImages.pdf

Alternatively, use this link to see a comparison between the two versions: https://visualstudio.microsoft.com/vs/mac/#vs_mac_table.

One of the most glaring shortcomings of Visual Studio for Mac is its lack of robust source control integration functionality. Developers often compensate for this using third-party tools such as Litracens, SourceTree, gmaster, and so on. That said, the Visual Studio for Mac experience improves with each release and includes more support for different application types. With the differences between the Mac and Windows versions shrinking, it is conceivable that within a few releases, the Mac and Windows experiences of Visual Studio will become nearly identical to VS Code.

Commonly referred to as VS Code, the Visual Studio Code product had humble beginnings as a text editor with support for optional plugins, similar to Atom or Sublime Text. Many developers consider it a lightweight tool specifically geared toward building and debugging modern web and cloud applications. However, it has grown into a full cross-platform (covering Linux, macOS, and Windows) editor that is free for both private and commercial use. It runs cross-platform, supports multiple programming languages, and has basic features such as syntax highlighting and code-completion aids (IntelliSense), as well as support for more advanced features such as debugging, refactoring, and code snippets, provided by plugins:

Figure 1.6 – VS Code – Windows

Figure 1.6 – VS Code – Windows

Both the popularity and the capabilities of VS Code have increased dramatically since Microsoft open-sourced this product back in late 2015. The integrated terminal is one thing many developers like about VS Code. This feature can be very convenient as you do not have to switch between applications to perform command-line tasks.

The ease of writing plug-ins, such as OmniSharp for debugging support, is credited with evolving this tool into (almost) a full-fledged IDE with support for many C# application types (including .NET Console, .NET Standard, and .NET MVC), as well as a number of other languages such as Java, Python, Ruby, and NodeJS. It supports common development operations including debugging, task running, and version control. It remains simplified to provide just what a developer needs for quick code-build-debug cycles.

The following screenshot depicts VS Code running on Linux, superimposed over a screenshot of VS Code running on macOS. Noteworthy is the striking similarity between the Windows, Mac, and Linux versions of VS Code. This makes for a consistent experience between platforms and makes shifting between them feel quite natural:

Figure 1.7 – VS Code on Mac (upper-left) and Linux (lower-right)

Figure 1.7 – VS Code on Mac (upper-left) and Linux (lower-right)

Microsoft has really made great strides to achieve a seamless experience here. The plugins are supported on each platform, the "look and feel" is seamless, and the capabilities are identical. With the cross-platform development and deployment features of .NET Core, and the IDE features and debugging of VS Code, many developers have made the switch to use this as their primary development environment. With the strength of the IDE, as well as the availability of strong plugins (see Chapter 12, Overviewing VS Code Extensions) the experience is pleasant, and the tool is very capable as a "daily driver."

Two is better than one

Lots of developers use both the full version of VS 2019 and install VS Code as well. The same code in most solutions can be opened and developed in either application. Some tasks, such as editing web files, may be done in VS Code, whereas the full version may be used for others, such as performing dependency validation.

Code examples in this book will alternate between the use of a "full version of VS 2019 and VS Code. The installation files for all versions described in this chapter can be downloaded from https://visualstudio.microsoft.com/downloads/.

 

GitHub Codespaces

A newcomer to the product flavors worth keeping an eye on is GitHub Codespaces, formerly called Visual Studio Codespaces, which provides cloudpowered development environments. In this case, an environment is considered the backend compute functions associated with software development, such as compiling and debugging. Working with this approach can be done using three possible clients: a browser-based editor, VS Code, or the Visual Studio IDE.

At the time of this writing, Codespaces is currently in beta and more information can be found at https://code.visualstudio.com/docs/remote/codespaces.

The bleeding edge

Like the public preview of GitHub Codespaces, VS 2019 and VS for Mac both have their own preview channels available. These allow developers to see and experiment with features that have not yet been released through the stable public channel. Similarly, VS Code has Insider Edition, a daily build that is essentially equivalent to the preview channels of the other flavors.

 

Summary

In this chapter, we overviewed the many flavors of Visual Studio that are available. We outlined the key differences between the various products Microsoft offers under the Visual Studio marketing umbrella to enable you to make an informed choice about which version will work best for you.

VS 2019 (Windows) is a very popular choice of IDE and has evolved considerably over its more than twenty-year existence. Simplified version differences and improved capabilities have made the Community version a usable tool for individuals and organizations that meet the licensing requirements. For those that don't, the Professional version is a relatively affordable version that is included in a number of Microsoft Developer Network (MSDN) subscriptions.

Visual Studio for Mac is a relatively new introduction but continues to improve with each release. The "look and feel" moves closer to the Windows version with each release, and the functionality continues to grow. For a full-featured IDE, it is becoming a very strong tool for non-Windows developers.

VS Code (Windows, Mac, and Linux versions) has grown into a very capable, useful IDE with support for multiple operating systems, multiple programming languages, and multiple workflows. From .NET to Python, NodeJS, Ruby, Java, and others, the support and strength of the plugins varies, but the core features of VS Code shine through and make the experience pleasant.

Regardless of your choice, operating system, or preferences, each tool comes with an excellent installation experience that makes it very easy for you to get up and running quickly. With Visual Studio now installed, you are ready to get started with keyboard shortcuts in the next chapter.

About the Authors

  • Paul Schroeder

    Paul Schroeder is a versatile application developer, speaker, author, and managing director at MSC Technology Consulting. Along with a multi-decade professional IT career, Paul has a bachelor's degree in computer science and an MBA, and has earned an MCSD certification for web development.

    Whether coding or not, Paul enjoys spending time with his marvelous and talented wife, Robin, herself a Xamarin developer/speaker who creates Bluetooth mesh mobile applications.

    Drawn to code generation, Paul is the inspiration behind CodeGenHero™, an innovative Visual Studio extension, covered in Chapter 14, Be Your Team's Hero with CodeGenHero. Follow Paul at PaulBSchroeder.

    Browse publications by this author
  • Aaron Cure

    Aaron Cure is a principal security consultant for Cypress Data Defense specializing in penetration testing, secure SDLC, static code review, and secure architectures. His certifications include CISSP, GPEN, GMOB, GWAPT, and GSSP-NET. As a global speaker and instructor, Aaron is passionate about helping developers understand and write safe and secure code.

    Aaron transitioned to programming after a decade as a Russian linguist and a satellite repair technician in the Army. He was an early adopter of technologies such as Mono and NHibernate for cross-platform development. Besides .NET, he has programmed in PHP, Python, Perl, TCL/TK, and Java.

    Currently, Aaron programs almost entirely in VS Code and .NET Core with projects transitioning to .NET 5.

    Browse publications by this author
Visual Studio 2019 Tricks and Techniques
Unlock this book and the full library for FREE
Start free trial