Replicate VS Code Extensions Using PowerShell

What is Visual Studio Code?

From Wikipedia,
Visual Studio Code is a source code editor developed by Microsoft for Windows, Linux and MacOS.
It includes support for debugging, embedded Git control, syntax highlighting, intelligent code completion, snippets, and code refactoring.
It is also customizable, so users can change the editor’s theme, keyboard shortcuts, and preferences.
It is free and open-source,although the official download is under a proprietary license.

Read more at https://code.visualstudio.com/docs

Extensions in Visual Studio Code

VS Code extensions let you add languages, debuggers, tools, add new features and themes to your installation to support your development workflow and experience.
Visual Studio Code has support for almost every major programming language.
You can find extensions to install using the Extensions View.
You can install extensions the ones you like, and disable extensions you don’t want to use all the time.

How do I get consistent VS Code experience?

It’s already available on Windows, Linux and MacOS. So even if you move between environments and type of operating systems you can still get the same VS Code experience.
To make it even seemless it would be good if you can get the extensions also available when you move between different machines. Like the way you get your roaming profile and desktop experience on Windows operating system.

There are few extensions available to solve this problem. The two prominently found on marketplace are,

  1. Settings Sync
  2. Extension Manager

I wanted to try something simple as I often create virtual machines for testing, training labs.
I have already automated the VS Code silent install using PowerShell Remoting. To extend that effort, I wanted to install extensions as well, so that once my virtual machine(s) is/are ready I can start using VS Code with same experience as my physical laptop.

I added following lines of code which using VS Code command line and PowerShell remoing command (Invoke-Command)

# Setting up credentials for remote session on VMs from Host Machine.    
$hostCredential = New-Object PSCredential("MachineName\Administrator", ('mypassword' | ConvertTo-SecureString -AsPlainText -Force))

# Find the Visual Studio Code Extensions Installed and store in variable   
$vscodeExtensions = code --list-extensions

# Install Desired Visual Studio Code Extensions
# Using foreach to iterate through list of extensions in $vscodeExtensions.
# Using Invoke-Command installs the extension on remote computer.
Invoke-Command -AsJob -ScriptBlock {
foreach ($vce in $using:vsccodeExtensions){
code --install-extension $vce 
}
} -ComputerName MachineName -Credential $hostCredential -Verbose 

# Verify Visual Studio Code Extensions are installed on remote machine
Invoke-Command -ScriptBlock {code --list-extensions} -ComputerName MachineName -Credential $hostCredential -Verbose

This slideshow requires JavaScript.

Notes:

  • I have tried this to replicate extensions found in Visual Studio Code installed on my Windows 10 laptop to Visual Studio Code installed on Windows 2012 Server Virtual Machine.
  • I have not tested this method with all possible extensions however I feel this should work unless there are any specific dependencies (missing) of extension blocking the installation.
  • You can use the same techique to uninstall extensions from remote command and code should look like
Invoke-Command -AsJob -ScriptBlock {
foreach ($vce in $using:vsccodeExtensions){
code --uninstall-extension $vce 
}
} -ComputerName MachineName -Credential $hostCredential -Verbose

Thats’s it for now. Thanks for reading!!!

PowerShell ISE on Ubuntu 14.04

In the last post covered the initial steps for

  • Installing PowerShell on Ubuntu 14.4
  • Running basic PowerShell Commands (cmdlets)

After doing that I was curious to understand how the PowerShell ISE works on open source. Some answers are available at PowerShell Magazine

search for “tmux”
search for “ISESteroids 2.6.1.0”

I have not worked on both of them so skip commenting on it for now.

I had heard about Visual Studio Code and PowerShell language support. I found some hints in the post Microsoft has open-sourced PowerShell for Linux, Macs. Repeat, Microsoft has open-sourced PowerShell

So with above, I tried testing script editing capabilities with Visual Studio Code on Ubuntu 14.04

Step 1 – Go To Visual Studio Code On Ubuntu 14.4 (https://code.visualstudio.com)

0

Step 2 – Download the .deb

1

2-1

Step 3 – Install Visual Studio Code

sudo dkpg –install ~/Downloads/code_1.4.0-1470329130_amd64.deb

2-2

2-3

Step 4 – Launch Visual Studio Code

3-0

3-1

Step 5 – Install the Extension For PowerShell

3-2

3-3

3-4

Step 6 – Enable PowerShell Extension

3-5

Step 7 – Restart Visual Studio Code

3-6

Step 8 – Launch Visual Studio Code and Save the Untitled file as Test1.ps1 file

3-7

Step 9 – Write PowerShell Commands. You will notice intellisence support available.

3-8

3-9

Step 10 – Go to Menu > View > Integrated Terminal (shortcut cntl + `)
It opens the bash terminal by default

3-10

Step 11 – Change Default Terminal from Menu > File > Preferences > User Settings

You will notice settings.json is empty. Whatever settings you add will override the default settings. I added entry to point to PowerShell.

3-11

3-12

Added following lines of code

//The path of the shell that the terminal uses on Linux.

“terminal.integrated.shell.linux”: “/opt/microsoft/powershell/6.0.0-alpha.9/powershell”

3-13

Step 12 – Restart Visual Studio Code

Step 13 – Go to Menu > View > Integrated Terminal (shortcut cntl + `)

It opens the PowerShell terminal by default now.

3-14

Step 14 – Type $PSVersionTable in console (terminal) and enter

3-15

Step 15 – In the editor type Get-ChildItem and Hit F8 key

It will run the command and produce the output but you won’t see it.

Step 16 – To see the output Go to Menu > View > Output

3-16

So Lessons Learnt are,

  • As of now, there is no official news on PowerShell ISE coming on open source.
  • Having said that, this is really a good beginning towards any client to any server management capabilities with PowerShell and Visual Studio Code (with PowerShell Extension). As it gets to final release and stabilizes in community, I expect to become more rich and smoothly integrated with open source editor (or with editing tool experiences)
  • The intellisence were not working consistently and fluently. There could be something about my VM. I will test later with another VM . I also check in communities for any such observations.

That’s it for now. I will continue exploring capabilities over next few days, So stay connected.