logo
logo

IntelliSense Support

In Sitecore Content Hub, the scripting SDK allows users to embed custom logic in the application and to automate common tasks. The scripts are written in C# and use the SDK to communicate with the application.

IntelliSense enables code completion when writing scripts using the Visual Studio Code tool. Code completion predicts the variable names, the functions and the properties that are available in the SDK libraries. It also indicates any invalid syntax in the script code.

The following image shows an example use case of the IntelliSense support.

IntelliSense configuration with Visual Studio Code

The following steps describe the configuration of IntelliSense in Visual Studio Code.

Prerequisites

  • Visual Studio Code.
  • .NET Core SDK
  • Dotnet-script

    Tip
    • To check if .NET Core SDK is installed on your system, run the following command in Windows Command Prompt: dotnet --info.
    • To check if dotnet-script is installed on your system, run the following command in Windows Command Prompt: dotnet tool list -g.
    • You can install Dotnet-script by running dotnet tool install -g dotnet-script (requires .NET Core SDK).

Steps

  1. Start Visual Studio Code.
  2. Go to Extensions (left menu) and search for 'omnisharp'.
  3. Select and install the C# for Visual Studio Code (powered by OmniSharp) extension.

  4. Create a new folder.

  5. Create a new file named NuGet.config in the created folder.
  6. Copy the following content to the NuGet.config file (replace the m-feed value):

    <?xml version="1.0" encoding="utf-8"?>
     <configuration>
         <packageSources>
             <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
             <add key="m-feed" value="https://stylelabs.myget.org/F/m-packages/auth/00000000-0000-0000-0000-000000000000/api/v3/index.json" />
         </packageSources>
     </configuration>
     
    Important

    In the configuration file, replace the m-feed value with your own pre-authenticated V3 URL by visiting this link.

  7. Start a Windows Command Prompt and navigate to the created folder.

  8. Run the command dotnet script init inside the folder using the Windows Command Prompt.

    Note

    The dotnet script init command creates 3 items in the folder:

    • '.vscode\launch.json': The VS Code launch configuration file.
    • 'omnisharp.json': The OmniSharp configuration file.
    • 'main.csx': A default script file.
  9. Copy the following content to the main.csx file.

    #! "netcoreapp2.0"
     #r "nuget: Stylelabs.M.Sdk,3.0.0-pre.711"
     using Stylelabs.M.Sdk;
     
    Note

    These imports should be included in every script where the Developer wants to use IntelliSense.

  10. Start or restart Visual Studio Code and go to the main.csx file.

    Important

    Restarting Visual Studio Code is necessary to load the included libraries.

  11. The IntelliSense should now be configured in Visual Studio code.

    Note

    Try using the IntelliSense in the script by clicking on Ctrl + Space.

Can we improve this article ? Provide feedback