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
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.
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.
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"' ;
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.
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 + `
Once you have displayed the Integrated Terminal, you will see that the Integrated Terminal default shell is the Command Shell (CMD.exe) as below.
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
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"
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.
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
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.
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
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
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.
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"' ;
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"
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:
- Select File > Open Folder…
- Select the cloned repository folder
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).