Skip to content

VS Code Editor Setup

When building a ScriptoForm it is recommended to use Microsoft Visual Studio Code (VS Code) for your code editing. For information on how to install, configure, customize, and use VS Code, please see the official documentation: Visual Studio Code Docs.
At a minimum, you should have the PowerShell extension installed in your VS Code environment. This extension provides syntax highlighting, IntelliSense, code snippets, and a host of other beneficial features when working with PowerShell script files.
Additionally, to help improve your developer experience, you may want to utilize one or both of the following items created by the author of the ScriptoForm and available in the GitHub repository:
  • ScriptoForm Code Snippets to help automate adding commonly used controls, event handlers, and PowerShell functions to your script file from within VS Code.
  • VS Code Editor Command functions and associated keyboard shortcuts to automate compiling your ScriptoForm or signing a script file from within VS Code.
VS Code snippets are templates of commonly used code blocks that can easily be inserted into a source code file. The ScriptoForm snippets include PowerShell script language templates for Controls, Event Handlers, and PowerShell functions that are designed to work with a ScriptoForm. VS Code snippets provide for optional tab stops that allow you to customize the template, immediately after being inserted, at each tab keystroke. For example, the variable name for a TextBox control will have a tab stop allowing you to type in your custom value. The ScriptoForm VS Code snippets make heavy use of these tab stops.
Many Microsoft .NET controls are designed to work in pairs. For example, the TextBox and Label controls are usually paired together (the Label is located in close proximity to the TextBox on the Form and usually describes the purpose of the TextBox). Because of these relationships, many of the ScriptoForm snippets will add both controls at the same time and the tab stops for that template are designed to change the properties of both controls similarly.

To add the custom ScriptoForm code snippets to your VS Code profile:

  1. Download the snippets file (“powershell.json”) from the SmartAceDesigns.ScriptoFormTemplates repository.
  2. Save the “powershell.json” file to your VS Code profile snippets folder. In a Windows OS, for the default VS Code profile, this is normally: “C:\Users\username\AppData\Roaming\Code\User\snippets”
    If you utilize custom profiles with VS Code, you will instead need to add this file to that snippets directory.
  3. The snippets will now be available in any PowerShell file (*.ps1|*.psd1|*.psm1) opened in VS Code code editor with focus by typing in the snippet name prefix (“scriptoform”) or using the “ctrl-space” keyboard shortcut and searching for snippets that start with that prefix.
  4. Where appropriate, Allman is included in the snippet name, prefix, and description to indicate the Allman coding style and OTB is used to indicate the One True Brace (OTB) coding sytle.

For more information on snippets, please see the official documentation: Snippets in Visual Studio Code.

Custom editor commands, created with Register-EditorCommand PowerShell functions, can be used to automate compiling your ScriptoForm or sign a script file with a code-signing certificate from within VS Code. These functions are normally defined in your “Microsoft.VSCode_profile.ps1” profile and can be called with a keyboard shortcut which is defined in the “keybindings.json” file in your VS Code profile.

To add the custom editor command functions to your VS Code profile:

  1. Download the VS Code PowerShell profile file (“Microsoft.VSCode_profile.ps1”) from the SmartAceDesigns.ScriptoFormTemplates repository.
  2. Save the “Microsoft.VSCode_profile.ps1” file to your PowerShell user profile directory:
    PowerShell 7.x: “C:\Users\username\Documents\PowerShell”
    Windows PowerShell 5.1: “C:\Users\username\Documents\Windows PowerShell”
  3. In the “Microsoft.VSCode_profile.ps1” file update the $CertificateFriendlyName variable with the friendly name of your code-signing certificate - by default it is set to “PowerShell”. If you do not sign PowerShell files, this value can remain unchanged.

To add the keyboard shortcuts, for the custom editor commands, to your keybindings file:

  1. Download the keybindings file (“keybindings.json”) from the SmartAceDesigns.ScriptoFormTemplates repository.
  2. Save the “keybindings.json” file to your VS Code profile folder. In a Windows OS, for the default VS Code profile, this is normally: “C:\Users\username\AppData\Roaming\Code\User”
    If you utilize custom profiles with VS Code, you will instead need to add this file to that directory.
  3. In the “keybindings.json” file update the “key:” property for each entry per you personal preferences if you do not wish to use the default keyboard shortcuts provided:
    alt-a: This keyboard shortcut compiles the executable for all supported .NET versions.
    alt-c: This keyboard shortcut compiles the executable for only the latest .NET version (currently STS 9.x).
    alt-s: This keyboard shortcut signs your ScriptoForm script file using the code-signing certificate with a friendly name assigned to the $CertificateFriendlyName variable in your “Microsoft.VSCode_profile.ps1” file.