Click or drag to resize

Using Visual Studio Code for Development

This topic describes how to setup a development environment - Visual Studio Code - for SDK functions such as plugins and WCF Link functions.

The topic will describe which tools to download and install, setup the development environment and create a new SDK project.

It is also possible to use the RelaxIS SDK Code Editor that is included in the RelaxIS installation. Using a third-party dedicated code editor however offers greater functionality and ease of development and is advisable in case you delve deeper into the possibilities of the SDK and start to build more and advanced plugins.

Prerequisites
  • Install the latest version of RelaxIS

Installing the required software

  1. Download and install Visual Studio Code

    Download Visual Studio Code

    Run the installer and follow the instructions to install the program.

    Start Visual Studio Code from one of the created shortcuts.

  2. In VSCode, find the Extension menu by clicking the Extension button on the left.

    Using the search function, find the extension 'C# Dev Kit' and install it.

    csharpextension

    This installs the 'C#' code extension as well as the '.NET Install Tool'

    The C# extension enables language features such as code completion or a solution explorer.

Setting up the plugin project

  1. Create a new plugin project:

    • Find the Command / Search bar in the title bar of the VS Code window and click inside.

    • Enter >.net: new project (or part of it) and accept with Enter when the option is selected

      vscode net new project

      Note that it may take a moment (>10s) for VS Code to load available project templates and show the upcoming list!

    • A list of project templates is shown. Enter and select class library.

      vscode class lib template
    • A folder browser will be shown to define where the new project is created.

      Find and create for example the folder My Documents\MyPlugins\MyFirstPlugin\

      Enter this created folder and press the Open button in the dialog

    • The VS Code command bar will now ask for a project name, enter e.g. MyFirstPlugin

      vscode project name
    • VS Code will then do a final confirmation step before creating the new project. Press Enter to accept.

      vscode newproject confirm
    • You may now be prompted with a dialog if you trust the authors of the files in this folder. Accept this dialog by clicking 'Yes, I trust the authors'.

  2. Alternative to step 1: Initialize a new C# project via the Terminal window:

    • Create a new empty folder where you want to place the new project

    • In VS Code, click File -> Open Folder and open the created folder

    • Click on View -> Terminal to show the terminal window

    • If not selected already, select 'powershell' on the right or create a new powershell terminal

    • Note that you are now in a command prompt in the previously created folder

      vscode terminal
    • Type in (confirm with Enter): dotnet new classlib --framework netstandard2.0

    • This creates a .csproj and a Class1.cs file in the specified location, similar to step 1.

  3. On the left in the navigation menu, minimize the folder explorer by clicking the 'MyFirstPlugin'-header. Then find the 'Solution Explorer' header and click it.

    Note: It may take a moment for the Solution Explorer header to show after opening a folder containing a .NET solution or project!

    solution explorer

    In the Solution Explorer, click on the project name (with the C# symbol next to it) to open the project file.

    vscode project bar

    Find the TargetFramework node, and change the value from net7.0 or netstandard2.0 to net472.

    XML: Before
    <TargetFramework>netstandard2.0</TargetFramework>
    XML: After
    <TargetFramework>net472</TargetFramework>

    If it exists, remove the ImplicitUsings tag or set it to disable, as it conflicts with the net472 target.

    XML: Remove or set to disable
    <ImplicitUsings>disable</ImplicitUsings>

    Add a project reference to the RelaxIS SDK.dll in the RelaxIS installation directory. Refer to the full code example of the project file as shown below for the syntax. If you installed RelaxIS to a different directory, please adjust the HintPath accordingly.

    XML: Full .csproj file
    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <TargetFramework>net472</TargetFramework>
        <LangVersion>11.0</LangVersion>
      </PropertyGroup>
    
      <ItemGroup>
        <Reference Include="RelaxIS_SDK">
          <HintPath>C:\Program Files (x86)\RelaxIS 3\RelaxIS SDK.dll</HintPath>
        </Reference>
      </ItemGroup>
    
    </Project>

Adding a new plugin

  1. Add a new class file to the project by clicking the New File button in the Solution Explorer

    vscode new file

    Select the Class template from the command bar and give it the name MyFirstAxisValue

    select class template
  2. Click on the newly added class in the solution explorer. Note, that the new file has a default namespace and class name. Adjust both to a more suitable value.

    first class names
  3. Let the class inherit from one of the plugin base classes, e.g. RelaxISPlugin_AxisValue.

    select inheritance class
  4. Use the VS Code quick-fix to automatically implement the methods and properties that need to be overriden in the new plugin.

    Move the cursor over the class name with the red squiggle, press Ctrl+. to bring up the quick-fix menu and select Implement abstract class.

    implement abstract class

    Fill the class with your code, or leave it default with the NotImplementedException code for now.

  5. Compile the plugin into a .dll file.

    In the command bar at the top enter and select >.NET: Build and press enter.

    net build command

    The compiler will compile the project and show any errors in the terminal output window. The compiled .dll file will be placed into the bin\Debug\ folder.

    To build the DLL with compiler optimizations ('Release' mode), open the powershell terminal via View -> Terminal and enter

    dotnet build -c Release

    The Release .dll will be placed into the folder bin\Release\

Next Steps

You are now set up to build the plugins in a modern development environment. This short tutorial is not intended to serve as a full tutorial for the features in VS Code. It is possible to further automate and customize the build process, build test applications for the library, make use all all features of the Roslyn compiler platform and so on.

Being one of the most used IDEs, a lot of tutorials are available online, both from Microsoft as well as from third-parties. We would like to encourage you to delve deeper on your own terms.

Likewise, this manual does not provide instructions for the programming language in general. You need to acquire some familiarity with the C# language in order to implement the actual plugin functions. As one of the most used programming languages, many great tutorials for C# are available online.

It is also possible to use Visual Basic.NET instead of C# as a programming language. To do so, the project needs to be created via the terminal as shown in Step 2 above. Here, specify the language when creating the project:

dotnet new classlib --framework netstandard2.0 --language VB

You may also want to find a dedicated extension for VB.NET language features. While VB.NET does not have any real drawbacks, it is no longer actively developed and it is recommended to use C# instead.

See Also

Other Resources

List of examples