Table Of ContentVisual Studio Code
Distilled
Evolved Code Editing for Windows,
macOS, and Linux
—
Second Edition
—
Alessandro Del Sole
Visual Studio
Code Distilled
Evolved Code Editing for
Windows, macOS, and Linux
Second Edition
Alessandro Del Sole
Visual Studio Code Distilled: Evolved Code Editing for Windows, macOS, and Linux
Alessandro Del Sole
Cremona, Italy
ISBN-13 (pbk): 978-1-4842-6900-8 ISBN-13 (electronic): 978-1-4842-6901-5
https://doi.org/10.1007/978-1-4842-6901-5
Copyright © 2021 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: Joan Murray
Development Editor: Laura Berendson
Coordinating Editor: Jill Balzano
Cover image designed by Freepik (https://www.freepik.com)
Distributed to the book trade worldwide by Springer Science+Business Media LLC, 1 New York Plaza, Suite
4600, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, email orders-ny@springer-sbm.
com, or visit https://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 https://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 via the book’s product page, located at www.apress.com/9781484269008. For more
detailed information, please visit https://www.apress.com/source- code.
Printed on acid-free paper
To my wife Angelica, you mean everything to me.
Table of Contents
About the Author �����������������������������������������������������������������������������������������������������xi
Acknowledgments �������������������������������������������������������������������������������������������������xiii
Introduction �������������������������������������������������������������������������������������������������������������xv
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 �������������������������������������������������������������������������������������8
Localization Support ��������������������������������������������������������������������������������������������������������������10
Updating Visual Studio Code ��������������������������������������������������������������������������������������������������11
Previewing Features with Insiders Builds �����������������������������������������������������������������������������13
Summary�������������������������������������������������������������������������������������������������������������������������������������14
Chapter 2: Getting to Know the Environment ���������������������������������������������������������17
The Welcome Page ����������������������������������������������������������������������������������������������������������������������18
The Code Editor ���������������������������������������������������������������������������������������������������������������������������19
Reordering, Resizing, and Zooming Editor Windows �������������������������������������������������������������20
The Status Bar ����������������������������������������������������������������������������������������������������������������������������20
The Activity Bar ���������������������������������������������������������������������������������������������������������������������������22
The Side Bar ��������������������������������������������������������������������������������������������������������������������������������22
The Explorer Bar ��������������������������������������������������������������������������������������������������������������������23
The Search Tool ���������������������������������������������������������������������������������������������������������������������27
The Git Bar �����������������������������������������������������������������������������������������������������������������������������28
v
Table of ConTenTs
The Run and Debug Bar ���������������������������������������������������������������������������������������������������������29
The Extensions Bar ����������������������������������������������������������������������������������������������������������������29
The Accounts Button��������������������������������������������������������������������������������������������������������������30
The Settings Button ���������������������������������������������������������������������������������������������������������������32
Navigating Between Files �����������������������������������������������������������������������������������������������������������32
The Command Palette �����������������������������������������������������������������������������������������������������������������33
The Panels Area ��������������������������������������������������������������������������������������������������������������������������35
The Problems Panel ���������������������������������������������������������������������������������������������������������������35
The Output Panel �������������������������������������������������������������������������������������������������������������������37
The Debug Console Panel ������������������������������������������������������������������������������������������������������37
Working with the Terminal �����������������������������������������������������������������������������������������������������38
Summary�������������������������������������������������������������������������������������������������������������������������������������40
Chapter 3: Language Support and Code Editing Features ��������������������������������������41
Language Support �����������������������������������������������������������������������������������������������������������������������41
Working with C# and C++ �����������������������������������������������������������������������������������������������������42
Basic Code Editing Features �������������������������������������������������������������������������������������������������������43
Working with Text ������������������������������������������������������������������������������������������������������������������43
Syntax Colorization ����������������������������������������������������������������������������������������������������������������44
Delimiter Matching and Text Selection ����������������������������������������������������������������������������������46
Code Block Folding ����������������������������������������������������������������������������������������������������������������46
Multicursors ��������������������������������������������������������������������������������������������������������������������������47
Reusable Code Snippets ��������������������������������������������������������������������������������������������������������47
Word Completion �������������������������������������������������������������������������������������������������������������������49
Minimap Mode �����������������������������������������������������������������������������������������������������������������������50
Whitespace Rendering and Breadcrumbs �����������������������������������������������������������������������������51
Markdown Preview ����������������������������������������������������������������������������������������������������������������53
Evolved Code Editing �������������������������������������������������������������������������������������������������������������������54
Working with IntelliSense ������������������������������������������������������������������������������������������������������55
Parameter Hints ���������������������������������������������������������������������������������������������������������������������57
Inline Documentation with Tooltips ���������������������������������������������������������������������������������������58
Go to Definition and Peek Definition ��������������������������������������������������������������������������������������60
vi
Table of ConTenTs
Go to Implementation and Peek Implementations �����������������������������������������������������������������62
Finding References ����������������������������������������������������������������������������������������������������������������63
Renaming Symbols and Identifiers ����������������������������������������������������������������������������������������67
Live Code Analysis �����������������������������������������������������������������������������������������������������������������68
Summary�������������������������������������������������������������������������������������������������������������������������������������76
Chapter 4: Working with Files and Folders�������������������������������������������������������������77
Visual Studio Code and Project Systems ������������������������������������������������������������������������������������77
Working with Individual Files ������������������������������������������������������������������������������������������������������78
Creating Files �������������������������������������������������������������������������������������������������������������������������80
File Encoding, Line Terminators, and Line Browsing �������������������������������������������������������������81
Working with Folders and Projects ���������������������������������������������������������������������������������������������82
Opening a Folder �������������������������������������������������������������������������������������������������������������������83
Opening �NET Solutions ���������������������������������������������������������������������������������������������������������85
Opening JavaScript and TypeScript Projects �������������������������������������������������������������������������86
Opening Loose Folders ����������������������������������������������������������������������������������������������������������87
Working with Workspaces �����������������������������������������������������������������������������������������������������������87
Creating Workspaces �������������������������������������������������������������������������������������������������������������89
Opening Existing Workspaces �����������������������������������������������������������������������������������������������90
Workspace Structure �������������������������������������������������������������������������������������������������������������90
Summary�������������������������������������������������������������������������������������������������������������������������������������91
Chapter 5: Customizing Visual Studio Code �����������������������������������������������������������93
Customizations and Extensions Explained ����������������������������������������������������������������������������������93
Customizing Visual Studio Code ��������������������������������������������������������������������������������������������������94
Theme Selection ��������������������������������������������������������������������������������������������������������������������95
Customizing the Environment ������������������������������������������������������������������������������������������������97
Customizing Keyboard Shortcuts ����������������������������������������������������������������������������������������106
Summary�����������������������������������������������������������������������������������������������������������������������������������110
vii
Table of ConTenTs
Chapter 6: Installing and Managing Extensions ���������������������������������������������������111
Installing Extensions �����������������������������������������������������������������������������������������������������������������111
Extension Recommendations ����������������������������������������������������������������������������������������������115
Useful Extensions ����������������������������������������������������������������������������������������������������������������116
Managing Extensions ����������������������������������������������������������������������������������������������������������������118
Configuring Extensions ��������������������������������������������������������������������������������������������������������119
Hints About Extension Authoring �����������������������������������������������������������������������������������������������121
Summary�����������������������������������������������������������������������������������������������������������������������������������122
Chapter 7: Source Control with Git �����������������������������������������������������������������������123
Source Control in Visual Studio Code ����������������������������������������������������������������������������������������123
Downloading Other Source Control Providers ���������������������������������������������������������������������124
Managing Repositories �������������������������������������������������������������������������������������������������������������125
Initializing a Local Git Repository ����������������������������������������������������������������������������������������125
Creating a Remote Repository ���������������������������������������������������������������������������������������������128
Handling File Changes ��������������������������������������������������������������������������������������������������������������130
Staging Changes �����������������������������������������������������������������������������������������������������������������132
Managing Commits �������������������������������������������������������������������������������������������������������������������133
Working with the Git Command-Line Interface �������������������������������������������������������������������������135
Creating and Managing Branches ���������������������������������������������������������������������������������������������136
Switching to a Different Branch ������������������������������������������������������������������������������������������138
Merging from a Branch ��������������������������������������������������������������������������������������������������������138
Hints About Rebasing Branches ������������������������������������������������������������������������������������������141
Deleting Branches ���������������������������������������������������������������������������������������������������������������141
Adding Power to the Git Tooling with Extensions ����������������������������������������������������������������������141
Git History ����������������������������������������������������������������������������������������������������������������������������142
GitLens ���������������������������������������������������������������������������������������������������������������������������������143
GitHub Pull Requests and Issues �����������������������������������������������������������������������������������������147
Working with Azure DevOps and Team Foundation Server �������������������������������������������������������149
Creating a Team Project�������������������������������������������������������������������������������������������������������149
Connecting Visual Studio Code to a Remote Repository������������������������������������������������������151
Summary�����������������������������������������������������������������������������������������������������������������������������������153
viii
Table of ConTenTs
Chapter 8: Automating Tasks �������������������������������������������������������������������������������155
Understanding Tasks �����������������������������������������������������������������������������������������������������������������155
Tasks Types �������������������������������������������������������������������������������������������������������������������������156
Running and Managing Tasks ����������������������������������������������������������������������������������������������157
The Default Build Task ���������������������������������������������������������������������������������������������������������162
Auto-Detected Tasks ������������������������������������������������������������������������������������������������������������163
Configuring Tasks ����������������������������������������������������������������������������������������������������������������165
Running Files with a Default Program ���������������������������������������������������������������������������������186
Summary�����������������������������������������������������������������������������������������������������������������������������������186
Chapter 9: Building and Debugging Applications: �NET 5 and
Other Platforms �����������������������������������������������������������������������������������189
Creating Applications ����������������������������������������������������������������������������������������������������������������189
Introducing �NET 5 ���������������������������������������������������������������������������������������������������������������190
Creating �NET 5 Projects ������������������������������������������������������������������������������������������������������191
Creating Projects on Other Platforms ����������������������������������������������������������������������������������196
Debugging Your Code ����������������������������������������������������������������������������������������������������������������198
Configuring the Debugger ���������������������������������������������������������������������������������������������������200
Managing Breakpoints���������������������������������������������������������������������������������������������������������203
Debugging an Application ����������������������������������������������������������������������������������������������������204
Summary�����������������������������������������������������������������������������������������������������������������������������������209
Chapter 10: Building Applications with Python ����������������������������������������������������211
Chapter Prerequisites ���������������������������������������������������������������������������������������������������������������211
Creating Python Applications �����������������������������������������������������������������������������������������������213
Running Python Code ����������������������������������������������������������������������������������������������������������215
Code Editing Features for Python ����������������������������������������������������������������������������������������������221
Enhanced Word Completion with IntelliSense ���������������������������������������������������������������������221
Understanding Function Parameters With Parameter Hints ������������������������������������������������222
Quickly Retrieving Type Definitions �������������������������������������������������������������������������������������222
Finding References ��������������������������������������������������������������������������������������������������������������223
Renaming Symbols ��������������������������������������������������������������������������������������������������������������224
Finding Code Issues with Linters �����������������������������������������������������������������������������������������225
ix
Table of ConTenTs
Advanced Code Editing with Pylance ����������������������������������������������������������������������������������������227
Managing Pylance Settings �������������������������������������������������������������������������������������������������230
Running Python Scripts �������������������������������������������������������������������������������������������������������������231
Summary�����������������������������������������������������������������������������������������������������������������������������������232
Chapter 11: Deploying Applications to Azure �������������������������������������������������������235
Introducing Azure Extensions ����������������������������������������������������������������������������������������������������235
Deploying Web Applications ������������������������������������������������������������������������������������������������������237
Installing Extensions ������������������������������������������������������������������������������������������������������������237
Signing into Azure Subscriptions �����������������������������������������������������������������������������������������238
Publishing Web Applications ������������������������������������������������������������������������������������������������240
Creating and Deploying Azure Functions ����������������������������������������������������������������������������������243
Configuring Visual Studio Code �������������������������������������������������������������������������������������������243
Creating Azure Functions �����������������������������������������������������������������������������������������������������245
Deploying Azure Functions ��������������������������������������������������������������������������������������������������251
Summary�����������������������������������������������������������������������������������������������������������������������������������256
Index ���������������������������������������������������������������������������������������������������������������������257
x