Visual Studio Code is What the Cool Kids Use

Today lets talk about Visual Studio Code and PowerShell integration. For those who are unfamiliar with Visual Studio code, its a free, lightweight source code editor that is available for Windows, Mac, and Linux. It ships with built-in support for JavaScript, Typescript, and Node.js. Support for many other languages is available through extensions. If you haven’t noticed, Visual Studio Code is what the cool kids are using.

Installation

You can use Visual Studio Code on multiple platforms. Ensure you meet the system requirements prior to install.

For those of you using macOS or Linux make sure PowerShell exists on your system. By following the Installing PowerShell instructions you can install PowerShell and launch a PowerShell session.

Open your favorite browser and go to the Visual Studio Code site. Once there, click on download, select the version of OS (in my case its Windows 10), save and run. The installation wizard will open, you will agree to the license terms, choose your install location, select additional tasks and install. Basically you can just click next all the way through the wizard for the default install. In a couple minutes you are ready to go. It really is that simple.

VS Code

Setup

There are a number of extensions in the Marketplace that you can install to enable additional languages, debuggers, and commands. You can perform a search for your favorite extension to get more details.

PowerShell Integration

Since I use PowerShell, one of the first things I wanted to do was to setup PowerShell language support so I could use this as my editor and run commands directly from VS Code. Some of the features include syntax highlighting, code snippets, Intellisense, run selected code using F8, launch online help using Ctrl+F1, and integrated terminal support to name just a few.

Launch VS Code, click on the extensions icon and type powershell. Click Install. Once the install is done click Reload and select Ok on the popup.

Extensions

After reloading we can go back in the extensions and we should see our PowerShell extension installed. You can disable and uninstall directly from here if desired.

PS extension

Now, wouldn’t it be nice if we could actually run PowerShell commands in the integrated terminal? If I type Ctrl+` then the integrated terminal opens. However, notice on the far right that cmd.exe is the default. We are going to change this by adding the sysnative PowerShell path to the user settings.

In VS Code, click File>Preferences>User Settings (select Workspace settings if project specific). This will open a split window with the default settings on the left and a settings.json file on the right. If we look in the default settings at the terminal.integrated.shell.windows setting we can see that its configured with cmd.exe as the default. To change this we will override it by adding the setting below within the brackets of the settings.json file on the right and save (Ctrl+S).

"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"

Reload by typing Ctrl+Shift+P and type reload window. Open the terminal and now you will notice it opens with PowerShell as the default and we can run commands.

Summary

Now that you see how easy it is to add extensions, you can go and add your favorite languages and debuggers. VS Code has integrated Git support as well. For additional info on VS Code click on the Getting Started link.