Your First Extension

06 Aug.,2024

 

Your First Extension

Your First Extension

In this topic, we'll teach you the fundamental concepts for building extensions. Make sure you have Node.js and Git installed.

For more information, please visit EXTENTOOL.

First, use Yeoman and VS Code Extension Generator to scaffold a TypeScript or JavaScript project ready for development.

  • If you do not want to install Yeoman for later use, run the following command:

    npx --package yo --package generator-code -- yo code

  • If you instead want to install Yeoman globally to ease running it repeatedly, run the following command:

    npm install --global yo generator-code

    yo code

For a TypeScript project, fill out the following fields:

# ? What type of extension do you want to create? New Extension (TypeScript)

# ? What's the name of your extension? HelloWorld

### Press <Enter> to choose default for all options below ###

# ? What's the identifier of your extension? helloworld

# ? What's the description of your extension? LEAVE BLANK

# ? Initialize a git repository? Yes

# ? Bundle the source code with webpack? No

# ? Which package manager to use? npm

# ? Do you want to open the new folder with Visual Studio Code? Open with `code`

Inside the editor, open src/extension.ts and press F5 or run the command Debug: Start Debugging from the Command Palette (&#;&#;P (Windows, Linux Ctrl+Shift+P)). This will compile and run the extension in a new Extension Development Host window.

Run the Hello World command from the Command Palette (&#;&#;P (Windows, Linux Ctrl+Shift+P)) in the new window:

You should see the Hello World from HelloWorld! notification showing up. Success!

If you aren't able to see the Hello World command in the debug window, check the package.json file and make sure that engines.vscode version is compatible with the installed version of VS Code.

Developing the extension

Let's make a change to the message:

  1. Change the message from "Hello World from HelloWorld!" to "Hello VS Code" in extension.ts.
  2. Run Developer: Reload Window in the new window.
  3. Run the command Hello World again.

You should see the updated message showing up.

Here are some ideas for things for you to try:

  • Give the Hello World command a new name in the Command Palette.
  • Contribute another command that displays current time in an information message. Contribution points are static declarations you make in the package.json Extension Manifest to extend VS Code, such as adding commands, menus, or keybindings to your extension.
  • Replace the vscode.window.showInformationMessage with another VS Code API call to show a warning message.

Debugging the extension

VS Code's built-in debugging functionality makes it easy to debug extensions. Set a breakpoint by clicking the gutter next to a line, and VS Code will hit the breakpoint. You can hover over variables in the editor or use the Run and Debug view in the left to check a variable's value. The Debug Console allows you to evaluate expressions.

You can learn more about debugging Node.js apps in VS Code in the Node.js Debugging Topic.

Next steps

In the next topic, Extension Anatomy, we'll take a closer look at the source code of the Hello World sample and explain key concepts.

You can find the source code of this tutorial at: https://github.com/microsoft/vscode-extension-samples/tree/main/helloworld-sample. The Extension Guides topic contains other samples, each illustrating a different VS Code API or Contribution Point, and following the recommendations in our UX Guidelines.

Using JavaScript

In this guide, we mainly describe how to develop VS Code extension with TypeScript because we believe TypeScript offers the best experience for developing VS Code extensions. However, if you prefer JavaScript, you can still follow along using helloworld-minimal-sample.

UX Guidelines

This is also a good time to review our UX Guidelines so you can start designing your extension user interface to follow the VS Code best practices.

Use the Visual Studio Code extension

Use the Visual Studio Code extension

In this article

Visual Studio Code is a lightweight but powerful source code editor that runs on your desktop and is available for Windows, macOS, and Linux. It comes with built-in support for JavaScript, TypeScript, and Node.js and has a rich ecosystem of extensions for other languages (such as C++, C#, Java, Python, PHP, and Go) and runtimes (such as .NET and Unity). For more information, see Get started with VS Code.

Visual Studio Code allows you to extend your capability through extensions. Visual Studio Code extensions can add more features to the overall experience. With the release of this feature, you can now use the Visual Studio Code extension to work with Power Pages.

If you want to learn more, please visit our website Extension Tools.

Visual Studio Code extension for Power Pages

The Power Platform Tools adds the capability to configure websites using Visual Studio Code, and use the built-in Liquid language IntelliSense enabling help with code completion, assistance, and hinting while customizing websites interface using Visual Studio Code. Using the Visual Studio Code extension, you can also configure portals through the Microsoft Power Platform CLI.

Note

  • You will need to ensure that node.js is downloaded and installed on the same workstation as Visual Studio Code for the Power Pages features to work.
  • Make sure that only Power Platform Tools are installed and not both Power Platform Tools and Power Platform Tools [PREVIEW]. See known issues for details.

Prerequisites

Before using the Visual Studio Code extension for Power Pages, you must:

  • Download, install, and configure Visual Studio Code. More information: Download Visual Studio Code

  • Configure your environment and system for Power Pages CI/CD support using CLI. More information: Microsoft Power Platform CLI (preview)

Install Visual Studio Code extension

After you install Visual Studio Code, you need to install the extension for the Power Platform tools plug-in for Visual Studio Code.

To install the Visual Studio Code extension:

  1. Open Visual Studio Code.

  2. Select Extensions from the left pane.

  3. Select the Settings icon from the top-right on the extensions pane.

  4. Search for and select Power Platform Tools.

  5. Select Install.

  6. Verify the extension is installed successfully from the status messages.

Download website content

To authenticate against a Microsoft Dataverse environment, and to download website content, refer to the tutorial Use Microsoft Power Platform CLI with Power Pages - download website content.

Tip

The Power Platform Tools Extension automatically enables using Microsoft Power Platform CLI commands from within Visual Studio Code through Visual Studio Integrated Terminal.

File icons

The Visual Studio Code extension for Power Pages automatically identifies and shows icons for files and folders inside the downloaded website content.

Visual Studio Code uses the default file icon theme which doesn&#;t show Power Pages specific icons. To view file icons specific to your websites, you&#;ll have to update the Visual Studio Code instance to use the Power Pages specific file icon theme.

To enable a portals-specific file-icon theme:

  1. Open Visual Studio Code.

  2. Go to File > Preferences > Theme > File Icon Theme

  3. Select the theme for PowerApps portals Icons.

Live preview

The Visual Studio Code extension enables a live preview option to view the Power Pages content page inside the Visual Studio Code interface during the development experience.

To see the preview, select from the top-right when having an HTML file open in edit mode.

The preview pane opens on the right side of the page being edited.

The preview feature requires that the other files are also open in the same Visual Studio Code session that makes up the HTML markup for the preview to show. For example, if only the HTML file is opened without the folder structure opened using Visual Studio Code, you&#;ll see the following message.

When this problem occurs, open the folder using File > Open folder and select the downloaded website content folder to open before you try to preview again.

Autocomplete

The autocomplete capability in the Visual Studio Code extension shows the current context being edited, and the relevant autocomplete elements through IntelliSense.

When customizing downloaded content using Visual Studio Code, you can now use IntelliSense for Power Pages Liquid tags.

Start by typing and a list of Liquid tags will appear, once you select the tag, it will be correctly formatted and ready for more input.

Liquid objects

You can see Liquid object code completions by entering {{ }}. With the cursor placed between the brackets, select <CTRL + space> to display a list of Liquid objects that you can select. If the object has more properties, you can enter a . and then select <CTRL + space> again to see specific properties of the Liquid object.

You can see Power Pages web template suggestions by place your cursor in the {include ' '} statement and select <CTRL> - space. A list of existing web templates will appear for you to select.

Create, delete, and rename website objects

From within Visual Studio Code, you're able to create, delete, and rename the following website components:

  • Web pages
  • Page templates
  • Web templates
  • Content snippets
  • New assets (Web files)

Create operations

You can use the context menu options to create new website components, right-select one of the supported objects, choose Power Pages and select the website object type you wish to create.

Alternatively, you can use the Visual Studio Code command palette by selecting Ctrl + Shift + P.

You'll need to specify more parameters to create the object.

Object Parameters Web pages Name, page template, parent page Page templates Name, web template Web templates Name Content snippets Name, and if the snippet will be HTML or text. New assets (Web files) Name, parent page, and select file to upload.

Rename and delete operations

From the file navigation, you can use the context menu to rename or delete Power Pages components.

Note

Deleted objects can be restored from the desktop recycle bin.

Limitations

The following limitations currently apply to the Power Platform Tools for portals:

  • Autocomplete features only support limited functionality.
  • Live preview doesn't support custom themes or Liquid objects.

See also

Power Pages support for Microsoft Power Platform CLI (preview)

The company is the world’s best telescopic tools supplier. We are your one-stop shop for all needs. Our staff are highly-specialized and will help you find the product you need.