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
-
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).
- To check if .NET Core SDK is installed on your system, run the following command in Windows Command Prompt:
Steps
- Start Visual Studio Code.
- Go to Extensions (left menu) and search for 'omnisharp'.
Select and install the C# for Visual Studio Code (powered by OmniSharp) extension.
Create a new folder.
- Create a new file named NuGet.config in the created folder.
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://slpartners.myget.org/F/m-public/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.Start a Windows Command Prompt and navigate to the created folder.
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.
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.
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.
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