Your First CounterStrikeSharp Plugin: Hello World
You do not need to be an experienced programmer to write a CounterStrikeSharp plugin. A working plugin is one small C# class and one project file. This guide takes you from nothing to seeing Hello World in your server console, and everything you learn here applies to every bigger plugin.
Install the .NET 8 SDK
CounterStrikeSharp plugins are written in C# on .NET 8. Install the .NET 8 SDK on your computer, then open a terminal and check that it works. The command prints the installed version, which should start with 8.
dotnet --version
Create the project
Create an empty folder, open a terminal inside it and generate a class library. The name you choose here becomes the name of your plugin DLL, so pick something clear and without spaces.
dotnet new classlib --name HelloWorldPlugin
Edit the project file
Open the generated .csproj file and replace its content with the one below. The important part is the reference to CounterStrikeSharp.API, which gives you access to the game. Delete the Class1.cs file that was generated, you will not need it.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.*" />
</ItemGroup>
</Project>
Write the plugin
Create HelloWorldPlugin.cs. Every plugin is a class that inherits from BasePlugin and gives itself a name and a version. The Load method runs once, when the server loads the plugin, and that is where your own code starts.
using CounterStrikeSharp.API.Core;
namespace HelloWorldPlugin;
public class HelloWorldPlugin : BasePlugin
{
public override string ModuleName => "Hello World Plugin";
public override string ModuleVersion => "1.0.0";
public override void Load(bool hotReload) { Console.WriteLine("Hello World!"); }}
Compile it
You can compile locally with dotnet build -c Release, or skip the setup and zip the folder (the project file and the .cs file) and upload it to our compiler. It restores the packages, builds the plugin and gives you a ready to use zip.
Copy it to the server
From the zip, copy only the plugin folder into addons/counterstrikesharp/plugins on your server. The folder and the DLL must have the same name. The dependencies folder in our zip is already provided by CounterStrikeSharp, so leave it out.
Check the console
Restart the server, or load the plugin while it runs. In the server console you should see your message. If you do not, run css_plugins list to see whether the plugin was found, and read our guide on plugins that do not load.
Hello World!
CounterStrikeSharp.API Loaded Successfully.
Change it and reload
Once the plugin works, edit the message, compile again and replace the DLL. CounterStrikeSharp supports hot reload, so on a development server you can often try a new version without restarting. The next steps are commands and game events, covered in our other guides.
Was this tutorial useful?
Barlap for the community.