Visual Studio Code

A guide to setting up Visual Studio Code for writing C# code for Streamer.bot with linting and autocomplete.

This tutorial provides a general step-by-step guide on setting up Visual Studio Code (VS Code) for writing C# code for Streamer.bot.

By following these instructions, you'll be able to write code with linting, which will help you catch errors early and ensure your code compiles before copying into Streamer.bot

Prerequisites

Download & Install Visual Studio Code

Configure Extensions

  • Launch Visual Studio Code if you haven't already
  • Open the Extensions menu
    • Keyboard Shortcut: Ctrl+Shift+X
    • Menu Bar: View > Extensions
  1. Install IntelliCode for C# Dev Kit - This dev kit will install all necessary extensions for C# development, including C#, C# Dev Kit, and .NET Install Tool
    undefined

Sign in to Visual Studio Account

  1. Open Command Palette with - Keyboard Shortcut: Ctrl+Shift+P - Menu Bar: View > Command Palette
  2. Type .NET: Sign into Visual Studio account and select it
    undefined
  3. Select Allow and it will open your web browser for you to log in with your Microsoft Account
    undefined
  4. Proceed to log in with Microsoft Account

Create new .NET Project

  1. Command Palette
    • Keyboard Shortcut: Ctrl+Shift+P
    • Menu Bar: View > Command Palette
  2. Type .NET: New Project and select it

undefined

  1. Select Console App

undefined

  1. Select a folder to save the new project folder into
  2. Write a name for the project and hit enter

undefined

  1. Press enter or select Create Project

undefined

  1. Open the new project folder.
    • Keyboard Shortcut: Ctrl+K, Ctrl+O
    • Menu Bar: File > Open Folder

This is what you should see when you open the Explorer undefined

Configure new project

  1. Open the Explorer
    • Keyboard Shortcut: Ctrl+Shift+E
    • Menu Bar: View > Explorer
  2. Navigate inside the open the .csproj file
  3. Replace with this template in the code block below
  4. Edit the Streamer.bot related dll filepaths to point to your Streamer.bot directory
  5. Save and close the .csproj file
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net472</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <LangVersion>latest</LangVersion>
    <NoWarn>CS0114</NoWarn> <!-- Ignore CS0114 errors -->
  </PropertyGroup>

  <ItemGroup>
    <!-- Include all DLLs in a specific directory in the build output -->
    <Reference Include="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.dll" />
    <Reference Include="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Core.dll" />
    <Reference Include="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Net.dll" />
    <Reference Include="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Net.Http.dll" />
    <Reference Include="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\netstandard.dll" />
    <Reference Include="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Windows.Forms.dll" />
    <Reference Include="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Drawing.dll" />
    <Reference Include="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.VisualBasic.dll" />
    <!-- List of dlls included with Streamer.bot -->
    <Reference Include="D:\overlays\streamerbot\Streamer.bot.Plugin.Interface.dll" />
    <Reference Include="D:\overlays\streamerbot\Streamer.bot.Common.dll" />
    <Reference Include="D:\overlays\streamerbot\Streamer.bot.Auth.dll" />
    <Reference Include="D:\overlays\streamerbot\Streamer.bot.EmoteHandlers.dll" />
    <Reference Include="D:\overlays\streamerbot\NAudio.dll" />
    <Reference Include="D:\overlays\streamerbot\NAudio.Core.dll" />
    <Reference Include="D:\overlays\streamerbot\Newtonsoft.Json.dll" />
    <Reference Include="D:\overlays\streamerbot\Twitch.Common.dll" />
    <Reference Include="D:\overlays\streamerbot\websocket-sharp.dll" />
    <!-- Example of a dll in the Streamer.bot dlls folder -->
    <!-- <Reference Include="D:\overlays\streamerbot\dlls\SharpOSC.dll" /> -->
  </ItemGroup>

</Project>

.csproj Notes

  • This file configures the project as a .NET Framework 4.7.2 project
  • I've added some basic assembly references that are used frequently
  • To point to your own Streamer.bot dlls, replace the directory with your own Streamer.bot directory and Streamer.bot dlls directory

Template for the .cs file

  1. Open the Explorer
    • Keyboard Shortcut: Ctrl+Shift+E
    • Menu Bar: View > Explorer
  2. Navigate inside the open the Program.cs file
  3. Replace your cs file with this template:
using Streamer.bot.Plugin.Interface;
using Streamer.bot.Plugin.Interface.Enums;
using Streamer.bot.Plugin.Interface.Model;
using Streamer.bot.Common.Events;
using System;

public class CPHInline : CPHInlineBase
{
    public bool Execute()
    {
        return true;
    }
}

.cs Notes

  • This is similar to the default code found in the Execute C# Code subaction
  • The first four lines are required in VS Code, but are used by default and not needed in Streamer.bot
  • Adding : CPHInlineBase after public class CPHInline seems to be the magic that gets VS Code to recognize the CPH methods (don't ask me why, I'm just a hobbyist programmer)

You can now write code with assistance from IntelliCode

  • You can type CPH. and it will automatically give you the available CPH methods
    • This uses the Streamer.bot.Plugin.Interface.dll of your Streamer.bot folder
    • The advantage of this is that you will have a current list of methods, classes, and enums available

undefined

  • Open Problems
    • Keyboard Shortcut: Ctrl+Shift+M
    • Menu bar: View > Problems
  • The Problems view will show you if there will be any compile errors
    • Look for any red error icons

undefined

- These errors will be compiler errors
  • You may notice some yellow warning icons

undefined

- These are only warnings and the code will still compile.

Copying code to Streamer.bot

  • Feel free to exclude the first four using statements from your code as they are automatically included in Streamer.bot's Execute C# Code subaction
  • After copying and pasting your code into the Execute C# Code subaction dialog, remember to remove:
: CPHInlineBase

from

public class CPHInline : CPHInlineBase
  • Make sure the code compiles successfully by clicking Compile
  • Click Save and Compile