Skip to main content

1E 23.7 (SaaS)

Installing and using Visual Studio Code with the Tachyon PowerShell Toolkit

How to install and use the Visual Studio Code development environment with the PowerShell Toolkit.

VS Code provides a far more feature-rich development and debugging environment than the old PowerShell Integrated Scripting Environment (ISE).

When you have completed this process, you will be able to author new PowerShell scripts using VS Code, and also debug these scripts, or the PowerShell toolkit itself.

Install Visual Studio Code
Installation

Download VS Code. It is recommended that you select the 64 bit system installer, which will make VS Code available to all users on the machine.

When installation is complete, you should have the option to run VS Code checked. Click Finish. VS Code should automatically launch.

Open the PowerShell Toolkit folder

Select File/Open Folder and browse to and select the folder in which the PowerShell Toolkit files are saved.

Open the Terminal Window

Select View/Terminal. You may need to press Enter for a prompt to appear.

By default, VS Code will attempt to run PowerShell Core (the new .NET core version of PowerShell). If this cannot be located, it will roll back to standard PowerShell.

Import the PowerShell Toolkit module

In the terminal window type

import-module .\pstachyontoolkit.psd1

To confirm that the module is loaded, type

get-tachyontoolkitversion

This should return the current toolkit version.

Click on the toolkit psm1 file

In the Explorer pane, click on the file pstachyontoolkit.psm1

Exit and re-enter VS Code

To ensure everything is correctly initialized, exit and then re-run VS Code. Note that your previous files are reloaded automatically.

Reload the PowerShell module

Repeat the commands in the section 'Import the PowerShell toolkit module' to reload the toolkit

Start debugging

The PSTachyonToolkit.psm1 file contents should still be visible on the first code tab.

Select Run/Start debugging from the VSCode menu

You will see an error 'Cannot run a document in the middle of a pipeline'. You can ignore this error

Set a breakpoint

Click ctrl+F and then type in get-toolkit

You should locate the code which contains the Get-TachyonToolkitVersion cmdlet.

Note

The cmdlet is called Get-ToolkitVersion in the code. This is because the module manifest file (PSTachyonToolkit.psd1) automatically adds a namespace prefix, Tachyon, to all cmdlets. This is so that the cmdlets do not conflict with any existing PowerShell cmdlets. However the code itself does not contain this prefix.

Scroll down to the line which reads

return $script:TOOLKITVERSION

Select Run/Toggle Breakpoint to set a breakpoint on this line

Run the command

get-tachyontoolkitversion

The breakpoint should be highlighted. If this does not occur, and you see an error dialogue on the bottom right, select Yes in the dialog to continue. Then exit and re-enter VS Code and reload the PowerShell toolkit (as in the section 'Import the PowerShell toolkit module') and then select Run/Start Debugging. Then re-enter the get-tachyontoolkitversion cmdlet

When the breakpoint is highlighted, press F5 to continue. The code should continue and the toolkit version will be displayed in the terminal window.

You now have VS Code configured for developing and debugging PowerShell.

Customization

Early versions of VS Code lacked a decent UI for customisation, requiring some fairly arcane JSON tweaks. This is now much improved, with most obvious customisation options being available via the File/Preferences menu.

Not being a personal fan of the light on dark default theme, I changed the colour scheme to Visual Studio (light). An additional feature which shows a tiny reduced version of the whole code base on the right hand side of the screen, called the minimap, is also something I don't personally find terribly useful, so I turn that off.

Finally, I personally prefer not to have the last active folder automatically reloaded each time I start VS Code, so I change the restore window option to none.

User installs of VS Code

It's possible to create a user install of VS Code that can be copied to a portable storage device such as a USB thumb drive, making it possible to take a configured copy of VS Code and simply copy it onto a target machine, as appropriate.