Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Hands-On Visual Studio 2022 - Second Edition

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

Product type Book
Published in Mar 2024
Publisher Packt
ISBN-13 9781835080443
Pages 336 pages
Edition 2nd Edition
Languages
Authors (2):
Hector Uriel Perez Rojas Hector Uriel Perez Rojas
Profile icon Hector Uriel Perez Rojas
Miguel Angel Teheran Garcia Miguel Angel Teheran Garcia
Profile icon Miguel Angel Teheran Garcia
View More author details

Table of Contents (19) Chapters

Preface 1. Part 1: Visual Studio Overview
2. Chapter 1: Getting Started with Visual Studio 2022 3. Chapter 2: Creating Projects and Templates 4. Chapter 3: Debugging and Profiling Your Apps 5. Part 2: Tools and Productivity
6. Chapter 4: Adding Code Snippets 7. Chapter 5: Coding Efficiently with AI and Code Views 8. Chapter 6: Using Tools for Frontend and Backend Development 9. Chapter 7: Styling and Cleanup Tools 10. Chapter 8: Publishing Projects 11. Part 3: GitHub Integration and Extensions
12. Chapter 9: Implementing Git Integration 13. Chapter 10: Sharing Code with Live Share 14. Chapter 11: Working with Extensions in Visual Studio 15. Chapter 12: Using Popular Extensions 16. Chapter 13: Learning Keyboard Shortcuts 17. Index 18. Other Books You May Enjoy

Coding Efficiently with AI and Code Views

Artificial intelligence (AI) is a vast and interesting field that allows us to improve our lifestyle in one way or another. We see, hear, and use it every day, and if you don’t believe it, ask yourself how many times you use the Google search engine throughout the day. Other places where you can find it are in photo-editing programs, where it is possible to remove, for example, the background of an image in an almost perfect way. Social networks are another perfect example of the use of artificial intelligence, as they are constantly processing the best recommendations for you to stay on them as long as possible.

Fortunately, AI has even reached new software development tools through predictive code integration, which allows us to choose the pieces of code we need at the right time. In VS, we have a powerful feature called Visual Studio IntelliCode that does this.

Similarly, with the recent launch of services such as ChatGPT and...

Technical requirements

To use IntelliCode, VS 2022 with the web development workload must be installed. You can find the code repositories at https://github.com/PacktPublishing/Hands-On-Visual-Studio-2022-Second-Edition/tree/main/Chapter%205.

Also, to be able to perform the procedure in the Code maps section, you will be required to use the Enterprise version of VS.

Likewise, the Code Map and Live Dependency Validation tools must be installed by the Visual Studio Installer. Select them as shown in Figure 5.1:

Figure 5.1 – Installation of the Code Map and Live Dependency Validation features

Figure 5.1 – Installation of the Code Map and Live Dependency Validation features

Now that we know the technical requirements, let’s learn how to work with them to get the most out of VS.

Understanding CodeLens

CodeLens is a powerful set of tools that is useful for finding references in code, identifying relationships between your different components, seeing the history of changes in the code, related bugs, code reviews, and unit tests, and so on.

In this section, we will analyze the most important tools of this feature. Let’s start by seeing how we can find references in our code.

Note

You can check if CodeLens is enabled by going to Tools | Options | Text Editor | All Languages | CodeLens, where you can see if the Enable CodeLens option is selected or not.

Finding references in code

CodeLens is presented in our code files from the first time we use VS. We can check this by going to any class, method, or property and verifying that a sentence appears, indicating the number of references in the project about it. In Figure 5.2, we can see that we have opened the WeatherForecastController.cs file, which shows us that three references have been found...

Working with code views

In addition to CodeLens, there are several windows that can help us examine the classes of a project and its members in a quicker way. In this section, you are going to learn about them and how they can help you in breaking down the code of a project in VS.

Class View

Class View is a window that allows you to see the elements of a VS project, such as namespaces, types, interfaces, enumerations, and classes, allowing you to access each of these elements quickly. Perhaps, if you have worked with small projects in VS, you might not see the Class View window as being of much use because you can easily navigate between a few classes from the Solution Explorer. But like me, if you work with solutions that can have up to 20 projects or more with hundreds of classes throughout the projects, then the Class View is an excellent option for examining code.

To access this window, you must select the View | Class View option from the menu, which will display the...

Using Visual IntelliCode

IntelliCode is the tool integrated into VS 2022, which allows you to write code faster, thanks to AI. It is a tool that has been trained with thousands of popular open source projects hosted on GitHub, and although it was already beginning to show a little of its potential in VS 2019, it is in VS 2022, where all the features have been implemented.

IntelliCode can suggest patterns and styles while you write code, giving you accurate suggestions according to the context in which you find yourself, so you can complete lines of code. IntelliCode is also able to show you the methods and properties you are most likely to use and supports completion in multiple programming languages, such as the following:

  • C#
  • C++
  • XAML
  • JavaScript
  • TypeScript
  • Visual Basic

Let’s examine how this amazing tool works in the following subsections.

Whole line completions

IntelliCode can be extremely useful in helping you complete entire lines...

Exploring GitHub Copilot

GitHub Copilot (hereinafter referred to as Copilot) is a novel AI tool for programmers that can help them write code faster. Unlike IntelliCode, Copilot can take the context of comments and underlying code to supplement your code. Copilot has been trained on billions of lines of code pulled from GitHub repositories, so its knowledge of various programming languages and platforms is quite extensive.

According to the GitHub site, after conducting an analysis on the use of Copilot, it has been found that developers are up to 96% faster in repetitive tasks and that 88% of those who use it feel more productive.

Something to take into account is that the Copilot license costs 10 dollars a month or 100 dollars a year for individuals and 19 dollars for companies, although you can try it for free by starting a free trial from their website:

https://github.com/features/copilot

Note

You can find Research: Quantifying the Impact of GitHub Copilot on Developer...

Summary

VS contains a set of tools and windows that can help us a lot while we are developing our projects, as well as extensions that we can install to exploit the power of Copilot in our hands.

We have seen how CodeLens can help us find references and relationships, both through code and visually. Likewise, we studied the Class View window, which helps us examine class members in projects. We have also seen how IntelliCode is a new addition to the IDE, which, through AI, helps us write code quickly through various suggestions.

You have seen how GitHub Copilot can be a great ally when writing code, as it can save you many hours of development by recommending code that you can complete, as well as instructing you through comments to give you functional pieces of code. Finally, GitHub Copilot Chat is a wonderful feature that can answer almost anything—questions about general programming, the current code, and exceptions.

In Chapter 6, Using Tools for Frontend and Backend...

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 2024 Publisher: Packt ISBN-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.
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}