Visual Studio Code: Getting Started with PowerShell


This week is a hectic week and I decided to post something which I have been setting up on my personal laptop at home lately just to get started with open source PowerShell in GitHub. Yes, I cannot afford Visual Studio for my personal leisure and therefore opted to try out Visual Studio Code instead and so far the experience is fantastic.

Therefore, I started documenting the journey and contributed a TechNet Wiki article for September before I forget about it while busy watching Microsoft Ignite broadcast in Atlanta.

You can either view this article from the Microsoft TechNet Wiki which may have any improvement updates by the TechNet community on the link below:

Or carry on reading this page on the original article which I have noted in my engineering journal with some explanations on the process.

The Original TechNet Wiki Article on Visual Studio Code: Getting Started with PowerShell

1. Introduction

Visual Studio Code was announced with a preview released on 29th April 2015 by Microsoft at 2015 Build conference. On 18th November 2015, Visual Studio Code was released under the OpenSource MIT License and its source code released to GitHub with Extension support announced. On 14th April 2016, Visual Studio Code graduated public preview stage and was released to public.

Visual Studio Code is a source code editor that supports a number of programming languages such as C, C++, C#, CSS, F#, HTML, Less, Java, JavaScript, JSON, Markdown, PHP, PowerShell, Python, Rust, Sass, Swift, Text, TypeScript, Visual Basic, XML, XSL and YAML. For users, Visual Studio Code has installable for multiple operating system platforms such as Windows, Debian, Ubuntu, Redhat, Fedora, CentOS, OS X Yosemite and El Capitan. It is also able to integrate with Git for GitHub.

2. Getting Started with Visual Studio Code

In this section, we will get started by downloading and installing Visual Studio Code just to get you started on working with Visual Studio Code.

2.1. Requirements

Since Visual Studio Code is available in multiple variety of Operating System platform, we high recommend you to find the correct package for your platform from the download site below:

2.2. Download Visual Studio Code using PowerShell

In this section, we will demonstrate how to download Visual Studio Code using PowerShell on Windows.

# Download Visual Studio Code from
#  https://code.visualstudio.com/#alt-downloads
Invoke-WebRequest `
    -Uri 'https://go.microsoft.com/fwlink/?LinkID=623230' `
    -OutFile 'C:\Temp\VSCodeSetup-stable.exe' ; 

2.3. Install Visual Studio Code silently using PowerShell

In this section, we will demonstrate how to install Visual Studio Code silently using PowerShell on Windows. You can also refer to the setup resource for Windows operating system below:

# Begin SILENT installation of
#  Visual Studio Code
Start-Process `
    -FilePath 'C:\Temp\VSCodeSetup-stable.exe' `
    -ArgumentList '/SILENT /LOG="C:\Temp\VSCodeSetup.log"' ; 

ms-vscode-step-1-download-and-install-using-powershell

2.4. Install Visual Studio Code on Non-Windows Operating System

In this section, we will provide the setup resources for Non-Windows operating system below:

Once Visual Studio Code has been installed, you can launch Visual Studio Code and have your first peek of the application.

ms-vscode-step-2-first-peek-of-visual-studio-code

2.5. Working with Integrated Terminal

In this section, we will demonstrate on changing the Integrated Terminal shell and using the Integrated Terminal to install extension from the marketplace.

2.5.1. Displaying the Integrated Terminal

In this section, we will discuss about how we can display the Integrated Terminal within Visual Studio Code and view the default shell for the first time.

To do this, you have 2 ways of displaying the Integrated Terminal:

  • Select View > Integrated Terminal
  • CTRL + `

ms-vscode-step-3-displaying-integrated-terminal

Once you have displayed the Integrated Terminal, you will see that the Integrated Terminal default shell is the Command Shell (CMD.exe) as below.

ms-vscode-step-4-first-peek-of-visual-studio-code-integrated-terminal-cmd

2.5.2. How to change the default Integrated Terminal to PowerShell

In this section, we will demonstrate on how we can modify the Integrated Terminal configuration to launch PowerShell instead of Command Shell by changing the User Settings in the Visual Studio Code Preferences.

To do this, you can use the Visual Studio Code graphical interface menu:

  • Select File > Preferences > User Settings

ms-vscode-step-5-displaying-user-settings

On the settings.json tab > add the following JSON line within the curly brackets:

// 64-bit PowerShell if available, otherwise 32-bit
    "terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"

ms-vscode-step-6-modifying-integrated-terminal-user-settings-for-powershell

Once you have added the overriding JSON syntax into setting.json file, you will have to save the settings.json and restarted the application.

To do this, you have 2 ways to save the file:

  • Select File > Save
  • CTRL + S

After saving the settings.json, you will have to exit Visual Studio Code and launch Visual Studio Code again.

Once Microsoft Visual Studio Code launched, display the Integrated Terminal again. Now, you will view the Integrated Terminal in PowerShell.

ms-vscode-step-7-first-peek-of-visual-studio-code-integrated-terminal-powershell

2.6. Working with Extension

In this section, we will demonstrate how to install the PowerShell extension from the marketplace and improve the Visual Studio Code experience with IntelliSense.

2.6.1. Installing Microsoft Visual Studio Code PowerShell extension

To install PowerShell extension from Marketplace using Integrated Terminal, we will launch the Integrated Terminal and issue the command below:

# Using the Integrated Terminal, we can install
#  the PowerShell extension by calling code.exe
#  with the appropriate parameter.
code --install-extension ms-vscode.PowerShell 

ms-vscode-step-8-installing-visual-studio-code-powershell-extension

Once the PowerShell extension has been installed into Visual Studio Code and restarted the Visual Studio Code, you can test the PowerShell IntelliSense by writing some PowerShell code like the example in the screenshot below.

ms-vscode-step-9-first-peek-of-visual-studio-code-powershell-intellisense

2.6.2. List installed Microsoft Visual Studio Code extensions

To list installed extensions using Integrated Terminal, we will launch the Integrated Terminal and issue the command below:

# Using the Integrated Terminal, we can list
#  the installed extension by calling code.exe
#  with the appropriate parameter.
code --list-extensions

ms-vscode-step-10-list-installed-visual-studio-code-extensions

2.6.3. Uninstalling a Microsoft Visual Studio Code extension

To uninstall extension using Integrated Terminal, we will launch the Integrated Terminal and issue the command below:

# Using the Integrated Terminal, we can uninstall the
#  Debugger for Chrome extension by calling code.exe
#  with the appropriate parameter.
code --uninstall-extension msjsdiag.debugger-for-chrome

ms-vscode-step-11-uninstalling-visual-studio-code-extension

3. Getting Started with GitHub on Visual Studio Code

In this section, we will get started by downloading and installing Git just to get you started on Visual Studio Code with Git integration in order to synchronise with GitHub repositories.

3.1. Requirement

With Git available in multiple variety of Operating System platform, we high recommend you to find the correct package for your platform from the download site below:

3.2. Download Git using PowerShell

In this section, we will demonstrate how to download Git for Visual Studio Code using PowerShell on Windows.

# Download Git from
#  https://git-scm.com/downloads
Invoke-WebRequest `
    -Uri 'https://github.com/git-for-windows/git/releases/download/v2.10.0.windows.1/Git-2.10.0-64-bit.exe' `
    -OutFile 'C:\Temp\Git-2.10.0-64-bit.exe' ;

3.3. Install Git silently using PowerShell

In this section, we will demonstrate how to install Git silently for Visual Studio Code using PowerShell on Windows. You can also refer to the setup resource for Windows operating system below:

# Begin SILENT installation of
#  Git version 2.10.0 X64
Start-Process `
    -FilePath 'C:\Temp\Git-2.10.0-64-bit.exe' `
    -ArgumentList '/SILENT /LOG="C:\Temp\GitSetup.log"' ;

ms-vscode-step-12-download-and-install-git-using-powershell

3.4. Use Git to clone a repository from GitHub

With Git and Visual Studio Code installed, we will demonstrate how to clone the Open Source PowerShell repository in GitHub using Integrated Terminal (PowerShell) or PowerShell console to your local disk and open the folder to view the entire Open Source PowerShell source code locally.

# Navigate to Git bin folder
Set-Location `
    -Path 'C:\Program Files\Git\bin' ; 
# Use Git to clone the PowerShell Repository
#  from GitHub to local personal folder
Git clone https://github.com/PowerShell/PowerShell.git "$Env:USERPROFILE\Documents\Visual Studio Code\PowerShell"

ms-vscode-step-13-use-git-to-clone-powershell-repository

Once the Git clone of the GitHub’s PowerShell repository has completed and you have open the folder using Visual Studio Code using the Visual Studio Code’s menu:

  1. Select File > Open Folder…
  2. Select the cloned repository folder

ms-vscode-step-14-use-visual-studio-code-to-open-cloned-repository-folder

4. Conclusion

After you have open the folder using Visual Studio Code, you will be able to use Visual Studio Code to view and work with the source code or even contribute to the PowerShell community through GitHub.

Welcome to the new Open Source Microsoft community, we have got you started with Visual Studio Code. If you think you can improve Visual Studio Code application further, we will welcome your feedback in GitHub (Microsoft/vscode).

ms-vscode-step-15-first-peek-of-the-opensource-powershell-repository

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s