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
- Download VS Code
- Install VS Code
- Launch VS Code
- Open Extensions
- Keyboard Shortcut:
Ctrl+Shift+X
- Menu Bar:
View > Extensions
- Keyboard Shortcut:
- Install
IntelliCode for C# Dev Kit
- This will also install the following Extension dependencies:
- C#
- C# Dev Kit
- .NET Install Tool
- Open Command Palette with
- Keyboard Shortcut:
Ctrl+Shift+P
- Menu Bar:
View > Command Palette
- Keyboard Shortcut:
- Type
.NET: Sign into Visual Studio account
and select it
- Select
Allow
and it will open your web browser for you to log in with your Microsoft Account
- Proceed to log in with Microsoft Account
- Command Palette
- Keyboard Shortcut:
Ctrl+Shift+P
- Menu Bar:
View > Command Palette
- Keyboard Shortcut:
- Type
.NET: New Project
and select it
- Select
Console App
-
Select a folder to save the new project folder into
-
Write a name for the project and hit enter
- Press enter or select
Create Project
- Open the new project folder.
- Keyboard Shortcut:
Ctrl+K, Ctrl+O
- Menu Bar:
File > Open Folder
- Keyboard Shortcut:
This is what you should see when you open the Explorer
- Open the Explorer
- Keyboard Shortcut:
Ctrl+Shift+E
- Menu Bar:
View > Explorer
- Keyboard Shortcut:
- Navigate inside the open the
.csproj
file - Replace with this template in the code block below
- Edit the Streamer.bot related dll filepaths to point to your Streamer.bot directory
- 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>
- 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
- Open the Explorer
- Keyboard Shortcut:
Ctrl+Shift+E
- Menu Bar:
View > Explorer
- Keyboard Shortcut:
- Navigate inside the open the
Program.cs
file - 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;
}
}
- 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
afterpublic 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 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
- This uses the
- Open
Problems
- Keyboard Shortcut:
Ctrl+Shift+M
- Menu bar:
View > Problems
- Keyboard Shortcut:
- The
Problems
view will show you if there will be any compile errors- Look for any red error icons
- These errors will be compiler errors
- You may notice some yellow warning icons
- These are only warnings and the code will still compile.
- 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