Visual Studio Code Distilled Evolved Code Editing for Windows, macOS, and Linux — Third Edition — Alessandro Del Sole
Visual Studio Code Distilled Evolved Code Editing for Windows, macOS, and Linux Third Edition Alessandro Del Sole
Visual Studio Code Distilled: Evolved Code Editing for Windows, macOS, and Linux ISBN-13 (pbk): 978-1-4842-9483-3 ISBN-13 (electronic): 978-1-4842-9484-0 https://doi.org/10.1007/978-1-4842-9484-0 Copyright © 2023 by Alessandro Del Sole This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Smriti Srivastava Development Editor: Laura Berendson Coordinating Editor: Mark Powers Copy Editor: Kezia Endsley Cover designed by eStudioCalamar Cover image designed by Freepik (www.freepik.com) Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza, Suite 4600, New York, NY 10004-1562, USA. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@ springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub (github.com/apress). For more detailed information, please visit http://www.apress. com/source-code. Printed on acid-free paper Alessandro Del Sole Cremona, Italy
To my wonderful wife, Angelica. You are my reason to live.
v About the Author ��������������������������������������������������������������������������������������������������� xiii Acknowledgments ���������������������������������������������������������������������������������������������������xv Introduction �����������������������������������������������������������������������������������������������������������xvii Chapter 1: Introducing Visual Studio Code ��������������������������������������������������������������� 1 Visual Studio Code, a Cross-Platform Development Tool �������������������������������������������������������������� 1 When and Why Visual Studio Code ������������������������������������������������������������������������������������������������ 2 Installing and Configuring Visual Studio Code ������������������������������������������������������������������������������ 4 Installing Visual Studio Code on Windows ������������������������������������������������������������������������������� 6 Installing Visual Studio Code on macOS ���������������������������������������������������������������������������������� 8 Installing Visual Studio Code on Linux ������������������������������������������������������������������������������������� 9 Localization Support �������������������������������������������������������������������������������������������������������������� 11 Updating Visual Studio Code �������������������������������������������������������������������������������������������������� 12 Previewing Features with Insiders Builds ����������������������������������������������������������������������������� 14 Visual Studio Code on Web ���������������������������������������������������������������������������������������������������� 16 Summary������������������������������������������������������������������������������������������������������������������������������������� 17 Chapter 2: Getting to Know the Environment ��������������������������������������������������������� 19 The Welcome Page ���������������������������������������������������������������������������������������������������������������������� 19 The Code Editor ��������������������������������������������������������������������������������������������������������������������������� 21 Reordering, Resizing, and Zooming Editor Windows ������������������������������������������������������������� 22 The Status Bar ���������������������������������������������������������������������������������������������������������������������������� 22 The Activity Bar ��������������������������������������������������������������������������������������������������������������������������� 23 The Side Bar �������������������������������������������������������������������������������������������������������������������������������� 24 The Explorer Bar �������������������������������������������������������������������������������������������������������������������� 24 The Search Tool ��������������������������������������������������������������������������������������������������������������������� 30 Table of Contents
vi The Git Bar ����������������������������������������������������������������������������������������������������������������������������� 31 The Run and Debug Bar ��������������������������������������������������������������������������������������������������������� 32 The Extensions Bar ���������������������������������������������������������������������������������������������������������������� 33 The Accounts Button�������������������������������������������������������������������������������������������������������������� 34 The Settings Button ��������������������������������������������������������������������������������������������������������������� 36 Navigating Between Files ����������������������������������������������������������������������������������������������������������� 36 The Command Palette ����������������������������������������������������������������������������������������������������������������� 37 The Panels Area �������������������������������������������������������������������������������������������������������������������������� 38 The Problems Panel ��������������������������������������������������������������������������������������������������������������� 38 The Output Panel ������������������������������������������������������������������������������������������������������������������� 40 The Debug Console Panel ������������������������������������������������������������������������������������������������������ 40 Working with the Terminal ����������������������������������������������������������������������������������������������������� 41 Summary������������������������������������������������������������������������������������������������������������������������������������� 43 Chapter 3: Language Support and Code Editing Features �������������������������������������� 45 Language Support ����������������������������������������������������������������������������������������������������������������������� 45 Working with C# and C++ ����������������������������������������������������������������������������������������������������� 46 Working with Python ������������������������������������������������������������������������������������������������������������� 47 Working with Julia ����������������������������������������������������������������������������������������������������������������� 48 Working with Go �������������������������������������������������������������������������������������������������������������������� 48 Basic Code Editing Features ������������������������������������������������������������������������������������������������������� 48 Working with Text ������������������������������������������������������������������������������������������������������������������ 49 Syntax Colorization ���������������������������������������������������������������������������������������������������������������� 50 Delimiter Matching and Text Selection ���������������������������������������������������������������������������������� 51 Code Block Folding ���������������������������������������������������������������������������������������������������������������� 52 Multicursors �������������������������������������������������������������������������������������������������������������������������� 52 Reusable Code Snippets �������������������������������������������������������������������������������������������������������� 53 Word Completion ������������������������������������������������������������������������������������������������������������������� 54 Minimap Mode ����������������������������������������������������������������������������������������������������������������������� 55 Sticky Scroll ��������������������������������������������������������������������������������������������������������������������������� 56 Whitespace Rendering and Breadcrumbs ����������������������������������������������������������������������������� 57 Markdown Preview ���������������������������������������������������������������������������������������������������������������� 58 Table of ConTenTs
vii Evolved Code Editing ������������������������������������������������������������������������������������������������������������������� 59 Working with IntelliSense ������������������������������������������������������������������������������������������������������ 60 Parameter Hints ��������������������������������������������������������������������������������������������������������������������� 62 Inline Documentation with Tooltips ��������������������������������������������������������������������������������������� 63 Go to Definition and Peek Definition �������������������������������������������������������������������������������������� 64 Go to Implementation and Peek Implementations ����������������������������������������������������������������� 66 Finding References ���������������������������������������������������������������������������������������������������������������� 67 Renaming Symbols and Identifiers ���������������������������������������������������������������������������������������� 70 Live Code Analysis ����������������������������������������������������������������������������������������������������������������� 72 Hints About IntelliCode ���������������������������������������������������������������������������������������������������������� 80 Summary������������������������������������������������������������������������������������������������������������������������������������� 80 Chapter 4: Working with Files and Folders������������������������������������������������������������� 81 Visual Studio Code and Project Systems ������������������������������������������������������������������������������������ 81 Working with Individual Files ������������������������������������������������������������������������������������������������������ 82 Creating Files ������������������������������������������������������������������������������������������������������������������������� 84 File Encoding, Line Terminators, and Line Browsing ������������������������������������������������������������� 86 Working with Folders and Projects ��������������������������������������������������������������������������������������������� 87 Opening a Folder ������������������������������������������������������������������������������������������������������������������� 88 Opening �NET Solutions ��������������������������������������������������������������������������������������������������������� 90 Opening JavaScript and TypeScript Projects ������������������������������������������������������������������������� 91 Opening Loose Folders ���������������������������������������������������������������������������������������������������������� 92 Working with Workspaces ����������������������������������������������������������������������������������������������������������� 92 Creating Workspaces ������������������������������������������������������������������������������������������������������������� 95 Opening Existing Workspaces ����������������������������������������������������������������������������������������������� 95 Workspace Structure ������������������������������������������������������������������������������������������������������������� 96 Security: Workspace Trust ����������������������������������������������������������������������������������������������������� 97 Summary����������������������������������������������������������������������������������������������������������������������������������� 101 Table of ConTenTs
viii Chapter 5: Customizing Visual Studio Code ��������������������������������������������������������� 103 Customizations and Extensions Explained �������������������������������������������������������������������������������� 103 Customizing Visual Studio Code ������������������������������������������������������������������������������������������������ 105 Theme Selection ������������������������������������������������������������������������������������������������������������������ 105 Customizing the Environment ���������������������������������������������������������������������������������������������� 107 Customizing Keyboard Shortcuts ���������������������������������������������������������������������������������������� 118 Creating Reusable Profiles �������������������������������������������������������������������������������������������������������� 123 Summary����������������������������������������������������������������������������������������������������������������������������������� 125 Chapter 6: Installing and Managing Extensions ��������������������������������������������������� 127 Installing Extensions ����������������������������������������������������������������������������������������������������������������� 127 Extension Recommendations ���������������������������������������������������������������������������������������������� 131 Useful Extensions ���������������������������������������������������������������������������������������������������������������� 133 Managing Extensions ���������������������������������������������������������������������������������������������������������������� 134 Configuring Extensions �������������������������������������������������������������������������������������������������������� 136 Writing Your First Extension ������������������������������������������������������������������������������������������������������ 138 Setting Up the Environment ������������������������������������������������������������������������������������������������� 139 Creating an Extension ���������������������������������������������������������������������������������������������������������� 140 Developing the Extension ���������������������������������������������������������������������������������������������������� 142 Running the Extension ��������������������������������������������������������������������������������������������������������� 145 Packaging Extensions���������������������������������������������������������������������������������������������������������� 147 Extension Development Summary��������������������������������������������������������������������������������������� 148 Summary����������������������������������������������������������������������������������������������������������������������������������� 149 Chapter 7: Source Control with Git ����������������������������������������������������������������������� 151 Source Control in Visual Studio Code ���������������������������������������������������������������������������������������� 151 Downloading Other Source Control Providers ��������������������������������������������������������������������� 152 Managing Repositories ������������������������������������������������������������������������������������������������������������� 153 Initializing a Local Git Repository ���������������������������������������������������������������������������������������� 154 Creating a Remote Repository ��������������������������������������������������������������������������������������������� 155 Handling File Changes �������������������������������������������������������������������������������������������������������������� 159 Staging Changes ����������������������������������������������������������������������������������������������������������������� 160 Table of ConTenTs
ix Managing Commits ������������������������������������������������������������������������������������������������������������������� 161 Working with the Git Command-Line Interface ������������������������������������������������������������������������� 163 Creating and Managing Branches ��������������������������������������������������������������������������������������������� 164 Switching to a Different Branch ������������������������������������������������������������������������������������������ 166 Merging from a Branch �������������������������������������������������������������������������������������������������������� 166 Hints About Rebasing Branches ������������������������������������������������������������������������������������������ 170 Deleting Branches ��������������������������������������������������������������������������������������������������������������� 170 Adding Power to the Git Tooling with Extensions ���������������������������������������������������������������������� 170 Git History ���������������������������������������������������������������������������������������������������������������������������� 171 GitLens ��������������������������������������������������������������������������������������������������������������������������������� 172 GitHub Pull Requests and Issues ����������������������������������������������������������������������������������������� 174 Working with Azure DevOps ������������������������������������������������������������������������������������������������������ 178 Creating a Team Project������������������������������������������������������������������������������������������������������� 178 Connecting Visual Studio Code to a Remote Repository������������������������������������������������������ 181 Summary����������������������������������������������������������������������������������������������������������������������������������� 182 Chapter 8: Automating Tasks ������������������������������������������������������������������������������� 185 Understanding Tasks ����������������������������������������������������������������������������������������������������������������� 185 Tasks Types ������������������������������������������������������������������������������������������������������������������������� 186 Running and Managing Tasks ���������������������������������������������������������������������������������������������� 187 The Default Build Task ��������������������������������������������������������������������������������������������������������� 192 Auto-Detected Tasks ������������������������������������������������������������������������������������������������������������ 192 Configuring Tasks ���������������������������������������������������������������������������������������������������������������� 194 Running Files with a Default Program ��������������������������������������������������������������������������������� 213 Summary����������������������������������������������������������������������������������������������������������������������������������� 213 Chapter 9: Building and Debugging Applications ������������������������������������������������� 215 Creating Applications ���������������������������������������������������������������������������������������������������������������� 215 The Status of Microsoft �NET ����������������������������������������������������������������������������������������������� 216 Creating �NET Projects ��������������������������������������������������������������������������������������������������������� 217 Creating Projects on Other Platforms ���������������������������������������������������������������������������������� 223 Table of ConTenTs
x Debugging Your Code ���������������������������������������������������������������������������������������������������������������� 225 Configuring the Debugger ��������������������������������������������������������������������������������������������������� 227 Managing Breakpoints��������������������������������������������������������������������������������������������������������� 230 Debugging an Application ���������������������������������������������������������������������������������������������������� 231 Configuring Debug Options �������������������������������������������������������������������������������������������������� 237 Summary����������������������������������������������������������������������������������������������������������������������������������� 238 Chapter 10: Building Applications with Python ���������������������������������������������������� 239 Chapter Prerequisites ��������������������������������������������������������������������������������������������������������������� 239 Creating Python Applications ����������������������������������������������������������������������������������������������� 241 Running Python Code ���������������������������������������������������������������������������������������������������������� 243 Code Editing Features for Python ���������������������������������������������������������������������������������������������� 250 Enhanced Word Completion with IntelliSense ��������������������������������������������������������������������� 250 Understanding Function Parameters with Parameter Hints ������������������������������������������������ 251 Quickly Retrieving Type Definitions ������������������������������������������������������������������������������������� 251 Finding References �������������������������������������������������������������������������������������������������������������� 252 Renaming Symbols �������������������������������������������������������������������������������������������������������������� 253 Finding Code Issues with Linters ����������������������������������������������������������������������������������������� 254 Advanced Code Editing with Pylance ���������������������������������������������������������������������������������������� 257 Managing Pylance Settings ������������������������������������������������������������������������������������������������� 260 Running Python Scripts ������������������������������������������������������������������������������������������������������������� 261 Summary����������������������������������������������������������������������������������������������������������������������������������� 262 Chapter 11: Deploying Applications to Azure ������������������������������������������������������� 263 Introducing Azure Extensions ���������������������������������������������������������������������������������������������������� 263 Deploying Web Applications ������������������������������������������������������������������������������������������������������ 265 Installing Extensions ������������������������������������������������������������������������������������������������������������ 265 Signing In to Azure Subscriptions ���������������������������������������������������������������������������������������� 266 Publishing Web Applications ������������������������������������������������������������������������������������������������ 268 Creating and Deploying Azure Functions ���������������������������������������������������������������������������������� 271 Configuring Visual Studio Code ������������������������������������������������������������������������������������������� 271 Creating Azure Functions ����������������������������������������������������������������������������������������������������� 273 Deploying Azure Functions �������������������������������������������������������������������������������������������������� 280 Table of ConTenTs
xi Deploying Docker Images ��������������������������������������������������������������������������������������������������������� 283 Docker Prerequisites ����������������������������������������������������������������������������������������������������������� 284 Creating the Application Image ������������������������������������������������������������������������������������������� 285 Uploading the Application Image to a Container Registry ��������������������������������������������������� 287 Deploying the Docker Image to Azure ��������������������������������������������������������������������������������� 290 Summary����������������������������������������������������������������������������������������������������������������������������������� 292 Chapter 12: Consuming AI Services ��������������������������������������������������������������������� 295 Introducing Azure for AI ������������������������������������������������������������������������������������������������������������� 296 General Considerations ������������������������������������������������������������������������������������������������������������� 297 Introducing Computer Vision ����������������������������������������������������������������������������������������������� 297 Setting Up Computer Vision Services ���������������������������������������������������������������������������������������� 297 Retrieving the Service Keys ������������������������������������������������������������������������������������������������� 302 Consuming AI Services with �NET ��������������������������������������������������������������������������������������������� 304 Setting Up Variables and Constants������������������������������������������������������������������������������������� 306 Creating Authenticated Service Clients ������������������������������������������������������������������������������� 308 Executing Image Analysis ���������������������������������������������������������������������������������������������������� 309 Running the Application������������������������������������������������������������������������������������������������������� 313 Consuming AI Services with JavaScript ������������������������������������������������������������������������������������ 315 Setting Up Variables and Constants������������������������������������������������������������������������������������� 317 Creating Authenticated Service Clients ������������������������������������������������������������������������������� 318 Executing Image Analysis ���������������������������������������������������������������������������������������������������� 319 Running the Application������������������������������������������������������������������������������������������������������� 322 Consuming AI Services with Python ����������������������������������������������������������������������������������������� 323 Setting Up Variables and Constants������������������������������������������������������������������������������������� 324 Creating Authenticated Service Clients ������������������������������������������������������������������������������� 325 Executing Image Analysis ���������������������������������������������������������������������������������������������������� 326 Running the Application������������������������������������������������������������������������������������������������������� 329 Summary����������������������������������������������������������������������������������������������������������������������������������� 330 Index ��������������������������������������������������������������������������������������������������������������������� 331 Table of ConTenTs
xiii About the Author Alessandro Del Sole is a senior software engineer for a healthcare company, building mobile apps for doctors and dialysis patients. He has been in the software industry for more than 20 years, focusing on Microsoft technologies such as .NET, C#, Visual Studio, and Xamarin. He has been a trainer, consultant, and a Microsoft MVP since 2008 and is the author of many technical books. He is a Xamarin Certified Mobile Developer, Microsoft Certified Professional, and a Microsoft Programming Specialist in C#.
xv Acknowledgments Thanks to Smriti Srivastava, Nirmal Selvaraj, Laura Berendson, and everyone else at Apress for the opportunity, renewed trust, and the great teamwork on this book. Special thanks to the technical editor Damien Foggon, who contributed to the quality and accuracy of the content. Special thanks to my wife Angelica, for her continuous and strong support.
xvii Introduction One of the most common requirements in software development today is building applications and services that run on multiple systems and devices, especially with the continued expansion of cloud and artificial intelligence services, and of architectures based on microservices. Developers have many options for building cross-platform and cross-device software, from languages to development platforms and tools. However, in most cases, such tools rely on proprietary systems, which result in strong dependencies. Moreover, most development tools target specific platforms and development scenarios. Microsoft Visual Studio Code takes a step forward by providing a fully featured development environment for Windows, macOS, and Linux that offers not only advanced coding features but also integrated tools. These tools span across the entire application lifecycle, from coding to debugging to team collaboration. The full tooling is consistent across these languages and frameworks, natively or via extensions, so that developers share the same experience regardless of the technology they use. With .NET 7 and with .NET MAUI recently released, and with artificial intelligence services becoming part of the modern software implementation, Visual Studio Code becomes even more important to support cross-platform development on multiple operating systems. In this book, developers with any skill level learn how to leverage Visual Studio Code to target scenarios such as web, cloud, and mobile development using the programming language of their choice. This book provides guidance on building apps for any system and any device. This includes managing the application lifecycle, as well as team collaboration.
1 CHAPTER 1 Introducing Visual Studio Code Visual Studio Code is not just another evolved notepad with syntax colorization and automatic indentation. Instead, it is a very powerful, code-focused development environment expressly designed to make it easier to write web, mobile, and cloud applications using languages that are available in different development platforms. It supports the application development lifecycle with a built-in debugger and integrated support for the popular Git version control engine. With Visual Studio Code, you can work with individual code files or with folders containing projects or loose files. This chapter provides an introduction to Visual Studio Code, giving you information on when and why you should use it. It includes details about installing and configuring the program on the different supported operating systems. Note In this book, I refer to the product using its full name, Visual Studio Code, as well as its friendly names, VS Code and Code, interchangeably. Visual Studio Code, a Cross-Platform Development Tool Visual Studio Code is the first cross-platform development tool in the Microsoft Visual Studio family that runs on Windows, Linux, and macOS. It is a free, open-source (https://github.com/microsoft/vscode), code-centric tool. This not only makes editing code files and folder-based project systems easier, but also facilitates writing cross-platform web, mobile, and cloud applications in the most popular platforms, such © Alessandro Del Sole 2023 A. Del Sole, Visual Studio Code Distilled, https://doi.org/10.1007/978-1-4842-9484-0_1
2 as Node.js and .NET. It also has integrated support for a huge number of languages and rich editing features such as IntelliSense, finding symbol references, quickly reaching a type definition, and much more. Visual Studio Code is based on Electron (https://electronjs.org/), a framework for creating cross-platform applications with native technologies. It combines the simplicity of a powerful code editor with the tools a developer needs to support the application lifecycle development, including debuggers and version control integration based on Git. Visual Studio Code is therefore a complete development tool, rather than being a simple code editor. For a richer development experience, consider Microsoft Visual Studio 2022 on Windows and Visual Studio 2022 for Mac on macOS, but Visual Studio Code can be really helpful in many situations. In this book, you learn how to use Visual Studio Code and how to get the most out of it; you discover how you can use it as a powerful code editor and as a complete environment for end-to-end development. Except where necessary to differentiate operating systems, figures are based on Microsoft Windows 10, but typically there is no difference in the interface on Windows 11, Linux, and macOS. Also, Visual Studio Code includes several color themes that style its layout. In this book, figures display the Light (Visual Studio) theme, so you might see different colors on your own screen if you choose a different color theme. Chapter 5 explains how to change the theme, but if you want to be consistent with the book’s figures, simply choose File ➤ Preferences ➤ Color Theme and select the Visual Studio 2019 Light Theme. It is worth mentioning that the theme you select does not affect the features described in this book. When and Why Visual Studio Code Before you learn how to use Visual Studio Code, explore the features it offers, and discover how it provides an improved code editing experience, you have to clearly understand its purpose. Visual Studio Code is not a simple code editor; rather, it is a powerful environment that puts writing code at its center. The main purpose of Visual Studio Code is to make it easier to write code for web, mobile, and cloud platforms for any developers working on Windows, Linux, or macOS, providing independence from proprietary development environments. For a better understanding of the nonproprietary nature of Visual Studio Code, let’s consider an example based on ASP.NET Core, the cross-platform, open-source technology able to run on Windows, Linux, and macOS that Microsoft produced to Chapter 1 IntroduCIng VISual StudIo Code
3 create portable web applications. Forcing you to build cross-platform, portable web apps with Microsoft Visual Studio 2022 would make you dependent on that specific integrated development environment (IDE). This also applies to the (free) Visual Studio 2022 Community edition. Conversely, though Visual Studio Code certainly is not intended to be a replacement for more powerful and complete environments, it can run on a variety of operating systems and can manage different project types, as well as the most popular languages. To accomplish this, Visual Studio Code provides the following core features: • Built-in support for coding in many languages, including those you typically use in cross-platform development scenarios, such as C# and JavaScript, with advanced editing features and support for additional languages via extensibility • Built-in debugger for Node.js, with support for additional debuggers (such as .NET and Julia) via extensibility • Version control based on the popular Git version-control system, which provides an integrated experience for collaboration, supporting code commits and branches In order to properly combine all these features into one tool, Visual Studio Code provides a coding environment based on folders, which makes it easy to work with code files that are not organized within projects and offers a unified way to work with different languages. Starting with this assumption, Visual Studio Code offers an advanced editing experience with features that are common to many supported languages, plus some features that are available to specific languages. As you’ll learn throughout the book, Code also makes it easy to extend its built-in features by supplying custom languages, syntax coloring, editing tools, debuggers, and much more via a number of extensibility points. It is a code-centric tool, with primary focus on web, cross-platform code. That said, it does not provide all of the features you need for full, more complex application development and application lifecycle management and it is not intended to be the best choice with some development platforms. If you have to make a choice, consider the following points: • Visual Studio Code can produce binaries and executable files only if the language you use has support to do so through a command-line interface (CLI), a compiler, and a debugger. If you use a language for which there is no extensive support (e.g., the open-source Go programming language, https://golang.org), Visual Studio Code Chapter 1 IntroduCIng VISual StudIo Code
4 cannot invoke a compiler. You can work around this by implementing task automation, discussed in Chapter 8, but this is different than having an integrated compilation process. • Except where provided by specific extensions, Visual Studio Code has no designers, so you can create an application user interface only by writing all of the related code manually. As you can imagine, this is fine for some languages and for some scenarios, but it can be very complicated with some kinds of applications and development platforms, especially if you are used to working with the powerful graphical tools available in Microsoft Visual Studio 2022. • Visual Studio Code is a general-purpose tool and is not the proper choice for specific development scenarios such as building Windows desktop applications. If your requirements are different, consider Microsoft Visual Studio 2022 or Microsoft Visual Studio 2022 for Mac instead, which are optimized for building, testing, deploying, and maintaining multiple types of applications. Now that you have a clearer idea of Code’s goals, you are ready to learn the amazing editing features that elevate it above any other code editor. Installing and Configuring Visual Studio Code Installing Visual Studio Code is an easy task. In fact, you can simply visit https:// code.visualstudio.com from your favorite browser, and the web page will detect your operating system, suggesting the appropriate installer. Figure 1-1 shows how the download page appears on Windows. Chapter 1 IntroduCIng VISual StudIo Code
5 Figure 1-1. The download page for Visual Studio Code Note Visual Studio Code can also run in portable Mode, which means that you can create a self-containing folder that can be moved across environments. Since this is a very specific scenario, it isn’t covered in this book; you can read the documentation (https://code.visualstudio.com/docs/editor/ portable) to learn the steps required to generate portable Mode. In the following sections, you learn some tips for installing Visual Studio Code on various supported systems. Note the latest stable release of Visual Studio Code at the time of this writing is version 1.76.0, released in February 2023. Chapter 1 IntroduCIng VISual StudIo Code
6 Installing Visual Studio Code on Windows Visual Studio Code can be installed on Windows 8, 10, and 11. For this operating system, Visual Studio Code is available with two installers: a global installer and a user-level installer. The global installer requires administrative privileges for installation and makes Code available to all users. The user-level installer makes Code available only to the currently logged-in user, but it does not require administrative privileges. The user-level installer is the choice I recommend, especially if you work within a corporate environment and you do not have administrative privileges to install software on your PC. The Download for Windows button that you can see in Figure 1-1 will automatically download the user-level installer. If you instead want to download the system-level installer, go to https://code.visualstudio.com/download and select the System Installer download that best fits your system configuration (32- or 64-bit, or ARM). Once the download has been completed, launch the installer and simply follow the guided procedure that is typical of most Windows programs. During the installation, you will be prompted to specify how you want to integrate shortcuts to Visual Studio Code in the Windows shell. In the Select Additional Tasks dialog box, make sure you select (at least) the following options: • Add “Open with Code” action to Windows Explorer file context menu, which allows you to right-click a code file in the Explorer and open a file with VS Code. • Add “Open with Code” action to Windows Explorer directory context menu, which allows you to right click a folder in the Explorer and open a folder with VS Code. • Add to PATH (available after restart), which adds the VS Code’s pathname to the PATH environment variable, making it easy to run Visual Studio Code from the command line without typing the full path. Note Some antivirus and system protection tools, such as Symantec endpoint protection, might block the installation of some files that are recognized as false positives. In most cases, this will not prevent Visual Studio Code from working, but Chapter 1 IntroduCIng VISual StudIo Code
Comments 0
Loading comments...
Reply to Comment
Edit Comment