Reader small image

You're reading from  Hands-On Visual Studio 2022 - Second Edition

Product typeBook
Published inMar 2024
PublisherPackt
ISBN-139781835080443
Edition2nd Edition
Right arrow
Authors (2):
Hector Uriel Perez Rojas
Hector Uriel Perez Rojas
author image
Hector Uriel Perez Rojas

Hector is an experienced senior developer, with more than 10 years of experience in developing desktop, web, and mobile solutions with the .NET platform. He was recognized with the Microsoft MVP award for two consecutive years in 2021 and 2022. He is an active member of the .NET community and is the founder of El Camino Dev and Devs School academies.
Read more about Hector Uriel Perez Rojas

Miguel Angel Teheran Garcia
Miguel Angel Teheran Garcia
author image
Miguel Angel Teheran Garcia

Miguel Angel Teheran Garcia is a solutions Architect and Technical Lead recognized as a Microsoft MVP, C# corner MVP, and Alibaba Cloud MVP. He is a member of the Avanet community in Medellín and an active member of tech events in Colombia. He has also been a speaker at different conferences around Latin America.
Read more about Miguel Angel Teheran Garcia

View More author details
Right arrow

Working with Extensions in Visual Studio

We cannot deny that VS’s native functionality for performing tasks, as we have seen so far, is phenomenal. However, there may be times when you want to extend the capabilities of the IDE with simple features, such as applying a new theme with custom colors, or complex functionality, such as code refactoring tools.

It is in these cases where VS extensions are of great help, which is why we will dedicate an entire chapter to analyzing their use.

The main topics we will cover are as follows:

  • Working with the Extensions tool
  • Searching for and installing extensions
  • Reviewing VS Marketplace
  • Setting up extensions
  • Creating a VS extension

Let’s start exploring the extensibility of VS, which is due to extensions.

Technical requirements

As this chapter focuses on showing the use of extensions in VS, a specific code repository is not required; however, you can have the repository located at https://github.com/PacktPublishing/Hands-On-Visual-Studio-2022-Second-Edition/tree/main/Chapter%207 at hand to make comparisons throughout this chapter.

Let’s learn how to work with the Extensions tool from VS.

Working with the Extensions tool

The main purpose of extensions in VS is that you can improve your day-to-day productivity with features that may be somewhat specific to particular tasks, such as providing suggestions for best practices in code, performing code cleanup, highlighting messages in the output window, adding visual features in code files, or interacting with SQLite databases. Allowing developers to create new features for VS and share them with the rest of the world is an excellent move on the part of the Microsoft team.

Important note

In this section, I will show you simple extensions to familiarize you with the concept of extensions. In Chapter 12, Using Popular Extensions, you will learn about the most used and preferred extensions by developers and how to work with them.

But how can we access these extensions? The most direct answer is through the Extensions tool, which you can find through the Extensions | Manage Extensions menu, as shown in Figure 11.1:

...

Searching for and installing extensions

The Extensions tool, which is shown in Figure 11.2, has a search box located at the top, where we can enter a search term to find extensions referring to some technology or tool. It is important to note that the search will be performed in the selected tab, as we discussed in the Working with the Extensions tools section.

If you want to perform a search among all the extensions, the best thing to do is to go to the Browse category and perform the search. In our example, we’ll search for extensions related to the keyword javascript:

Figure 11.2 – A list of results in the Extensions tool

Figure 11.2 – A list of results in the Extensions tool

The order of the list of extensions will appear according to the drop-down item at the top, which appears as sorting by Relevance by default. However, we can also select other options, such as displaying by Installs, Updated date, Trending, or Rating.

Let’s do another test, this time to install an extension...

Reviewing VS Marketplace

VS Marketplace is the online place to find and install extensions for VS 2022. In this marketplace, you can also find extensions for other products of the VS family, such as VS Code and Azure DevOps. You can access the marketplace via https://marketplace.visualstudio.com/vs.

Once you enter the portal, you will have a very different user interface to the Extensions tool, but the core operation is the same. In the main portal, you will be able to see the different extensions sorted by Featured, Trending, Most Popular, and Highest Rated.

To test the marketplace, let’s search for the term icons and see the list of results. Although the list currently yields around 60 results, not all extensions are compatible with the most modern version of VS. Therefore, it is recommended to apply the filter for Visual Studio 2022, as shown in Figure 11.7:

Figure 11.7 – Filtering VS versions in the marketplace

Figure 11.7 – Filtering VS versions in the marketplace

Once the filter has...

Setting up extensions

Unfortunately, there is no standardized way to configure a VS extension since each extension is unique and serves specific purposes. What is true is that most extensions will add configuration options for the extension, either through a special window or from the configuration options.

The best way to learn about these configuration options is through the extension page itself. For example, in the case of the Visual Studio Iconizer extension, which we installed in the Reviewing VS Marketplace section, the initial behavior is to show only the icons on the tabs. The extension page tells us that this behavior can be changed to show the text of the tab next to the icon added by the extension. This can be done via the options that have been added through the Tools | Options | Environment | Iconizer menu, as shown in Figure 11.12:

Figure 11.12 – The Iconizer extension options

Figure 11.12 – The Iconizer extension options

Most extensions create a section, as shown in the preceding...

Creating a simple VS 2022 extension

Now that you know how to install extensions in VS 2022, you may be wondering how to create an extension for VS. Although this process may sound very complex, fortunately, the team behind VS 2022 has been working on a new framework called VisualStudio.Extensibility. Although currently in the preview stage, it is the future as far as creating extensions for VS 2022 is concerned.

Some of the new features and characteristics of this framework are as follows:

  • Improved performance and reliability
  • A modern, asynchronous API
  • Improved stability for testing
  • A simplified architecture with consistent APIs

To create an extension using VisualStudio.Extensibility, you must search for and install the VisualStudio.Extensibility Project System extension via Extension Manager, as you saw in the Searching for and installing extensions section.

Once the new extension has been installed and VS has been restarted, in the template selector...

Summary

In this chapter, we have seen that extensions are a way in which we can extend the functionality of VS to improve our user experience and optimize development time. We have tested a few extensions that have completely changed some of the IDE’s functionality, such as previewing colors in .css files, renaming tabs to icons, and creating themes for distribution.

We have also reviewed how to search for and install extensions, both from the Extensions tool and VS Marketplace. We analyzed how extensions are regularly configured, and finally, we created a new extension that has allowed you to experience the process that’s involved in creating extensions with the new Visual.Studio Extensibility framework.

In Chapter 12, Using Popular Extensions, we will delve even deeper into the topic of extensions, analyzing which ones are the most popular because of their usefulness in daily development.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Hands-On Visual Studio 2022 - Second Edition
Published in: Mar 2024Publisher: PacktISBN-13: 9781835080443
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Authors (2)

author image
Hector Uriel Perez Rojas

Hector is an experienced senior developer, with more than 10 years of experience in developing desktop, web, and mobile solutions with the .NET platform. He was recognized with the Microsoft MVP award for two consecutive years in 2021 and 2022. He is an active member of the .NET community and is the founder of El Camino Dev and Devs School academies.
Read more about Hector Uriel Perez Rojas

author image
Miguel Angel Teheran Garcia

Miguel Angel Teheran Garcia is a solutions Architect and Technical Lead recognized as a Microsoft MVP, C# corner MVP, and Alibaba Cloud MVP. He is a member of the Avanet community in Medellín and an active member of tech events in Colombia. He has also been a speaker at different conferences around Latin America.
Read more about Miguel Angel Teheran Garcia