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.
Install the latest version of RelaxIS
Download and install Visual Studio Code
Run the installer and follow the instructions to install the program.
Start Visual Studio Code from one of the created shortcuts.
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.
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.
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
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.
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
VS Code will then do a final confirmation step before creating the new project. Press Enter to accept.
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'.
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
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.
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!
In the Solution Explorer, click on the project name (with the C# symbol next to it) to open the project file.
Find the TargetFramework node, and change the value from net7.0 or netstandard2.0 to net472.
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net472</TargetFramework>
If it exists, remove the ImplicitUsings tag or set it to disable, as it conflicts with the net472 target.
<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.
<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>
Add a new class file to the project by clicking the New File button in the Solution Explorer
Select the Class template from the command bar and give it the name MyFirstAxisValue
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.
Let the class inherit from one of the plugin base classes, e.g. RelaxISPlugin_AxisValue.
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.
Fill the class with your code, or leave it default with the NotImplementedException code for now.
Compile the plugin into a .dll file.
In the command bar at the top enter and select >.NET: Build and press enter.
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\
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.