Automatically build and deploy your changes
Adapted from the original guide.
During development of your plugin, you may find yourself repeating a workflow similar to the following:
- Make a change to your plugin
- Run your build task (ex.
dotnet build
) - Upload plugin DLLs to your server using an FTP client
- Alt-tab to the game
- Test your changes
- Repeat
Iterating on your plugin this way is painfully slow and impacts your productivity. Below, you will find a guide and recommendations on how to setup your dev environment to watch for file changes and automatically update plugin files on your server as you work. By following this guide, your new workflow should look like this:
- Make a change to your plugin
- Alt-tab to the game
- Test your changes
- Repeat
Caution
Exercise caution when developing your plugin while using this workflow. Build time errors are mostly caught by .NET SDK before files are committed but incomplete implementation may lead to issues such as server crashes. Avoid using this workflow on a production server meant for players.
Setup
1. Build plugin on file changes
The dotnet
CLI, included with the .NET SDK, offers a convenient command for
automatically watching for source file changes. If you have access to the dotnet
CLI, run the following command to start watching your source code.
dotnet watch build --project path/to/projectName.csproj
By default, dotnet watch
executes the dotnet run
command on file changes
so specifying build
as the first argument is required.
Your plugin will now build automatically on file change. By default, your builds
should be placed in bin/<config>/<framework>
in the same directory as your .csproj
.
projectDirectory
├── projectName.csproj
├── bin
│ └── Debug
│ └── net8.0
│ └── PLUGIN BUILDS HERE
Tip
You can have your plugin build to a more convenient location by setting the
<OutDir>
build property in your .csproj
file.
Example: <OutDir>./build/$(MSBuildProjectName)</OutDir>
2. Setup automatic uploads
Using WinSCP (Windows only)
Once connected to your server:
- Go to the
Commands
tab at the top of the WinSCP window and clickKeep Remote Directory up to Date
. - Select the plugin build directory containing your DLLs.
- Select the plugin destination.
(
csgo/addons/counterstrikesharp/plugins/<projectName>
) - Click
Start
Important
For WSL users: Applications running on Windows, such as WinSCP, cannot watch your Linux subsystem for file changes. Try using this workaround or consider moving development to Windows.
Using lsyncd
(Linux)
TODO: in-depth guide for setting up lsyncd
Learn more about lsyncd
: https://github.com/lsyncd/lsyncd
Using WinSCP while developing in WSL
Run the following watch command in place of the one mentioned in Step 1 to build to a directory in your Windows filesystem
dotnet watch build --project path/to/<projectName>.csproj --property:OutDir=/mnt/<drive-letter>/some/path/<projectName>`
and have WinSCP in Step 2 watch that path instead.