Guide Guide - A Script for Building C# Mod with Docker

jhj0411jhj

Newcomer
Hello, I'm new to Stardew Valley modding and C#.

I've written a batch script that uses Docker to build plugins (on Windows), making it easier for users who don't use Visual Studio or prefer not to install .NET directly. The script is based on the `mcr.microsoft.com/dotnet/sdk:6.0` Docker image. macOS and Linux users can adapt it for their systems with some modifications.

For me, using AI coding tools along with this zero-cost build script has made it possible to quickly modify existing mods, even though I'm not very familiar with C# syntax or modding in detail. I hope this script can be helpful to others. I'm also wondering if it could be added to any modding tutorial to help more modding beginners get started.

Core command:
Code:
docker run --rm ^
  -v "%cd%:/workspace" ^
  -v "%GAME_PATH%:/game:ro" ^
  -v "%CACHE_DIR%:/root/.nuget/packages" ^
  -v "%DEPLOY_DIR%:/game/Mods" ^
  -w /workspace/%PROJECT_NAME% ^
  -e NUGET_PACKAGES=/root/.nuget/packages ^
  mcr.microsoft.com/dotnet/sdk:6.0 ^
  sh -c "echo '<Project><PropertyGroup><GamePath>/game</GamePath></PropertyGroup></Project>' > ~/stardewvalley.targets && dotnet build --configuration Release"
Usage:
1. Create a `build.bat` file outside the project directory, and copy the following code (Full content of `build.bat`) into it.
2. Modify the `GAME_PATH` variable to point to your Stardew Valley installation directory.
3. Modify the `PROJECT_NAME` variable to match the project directory.
4. Run `build.bat` to build the mod.
5. The mod will be deployed in the `Mods-deploy` directory. The release files will be in the `bin\Release\net6.0` directory.

Full content of `build.bat`:
Code:
@echo off

set PROJECT_NAME=Your-Project-Dir
set GAME_PATH=C:\Steam\steamapps\common\Stardew Valley

set CACHE_DIR=%cd%\nuget-cache
set DEPLOY_DIR=%cd%\Mods-deploy

if not exist "%CACHE_DIR%" (
    echo Creating NuGet cache directory: %CACHE_DIR%
    mkdir "%CACHE_DIR%"
)

if not exist "%DEPLOY_DIR%" (
    echo Creating deploy directory: %DEPLOY_DIR%
    mkdir "%DEPLOY_DIR%"
)

echo Building %PROJECT_NAME% mod using official .NET 6.0 SDK image...
echo Game path: %GAME_PATH%
echo NuGet cache: %CACHE_DIR%
echo Deploy directory: %DEPLOY_DIR%
echo.

docker run --rm ^
  -v "%cd%:/workspace" ^
  -v "%GAME_PATH%:/game:ro" ^
  -v "%CACHE_DIR%:/root/.nuget/packages" ^
  -v "%DEPLOY_DIR%:/game/Mods" ^
  -w /workspace/%PROJECT_NAME% ^
  -e NUGET_PACKAGES=/root/.nuget/packages ^
  mcr.microsoft.com/dotnet/sdk:6.0 ^
  sh -c "echo '<Project><PropertyGroup><GamePath>/game</GamePath></PropertyGroup></Project>' > ~/stardewvalley.targets && dotnet build --configuration Release"

if %ERRORLEVEL% EQU 0 (
    echo.
    echo Build successful!
    echo Release location: %cd%\%PROJECT_NAME%\bin\Release\net6.0\
    echo Deployed files location: %DEPLOY_DIR%\
    echo You can copy the mod folder from %DEPLOY_DIR% to your Stardew Valley Mods folder.
) else (
    echo.
    echo Build failed. Please check the error messages above.
)

pause
 

SomeoneEls

Farmer
This sounds pretty cool having a release directory, but at the same time I have a ton of questions of what this is used for?


Also, If this is a visual studio supplement, there are some things you might want to consider.

If this doesnt use smapi, the smapi console gives us a ton of stuff, including

1. Seeing if a mod is outdated or incompatible
2. Debugging command support for other mods
3. Corruption detection

Currently visual studio has a system where you can monitor cpu usage, GC collections, threads, and a lot more. So if it can't work with the monitoring systems of other ides you miss out on that. But, I dont use it that often since its mostly for figuring out why your performance is bad so yeah :p

(Just to be clear, visual studio insiders community edition is free and uses intellisence (auto complete) and intelicode (AI assistance, optional). For the terms and conditions, you can do whatever if your an individual, its just that if you are a organization they do have some rules.)
 
Last edited:

SomeoneEls

Farmer
Anyways, this is really cool! Sorry if this is a lot, I just want to know more about it, since I'm not sure on what the script is for
 
Last edited:

jhj0411jhj

Newcomer
Thanks for bringing up those points! Let me clarify a few things about the script and its purpose.

About the script: it makes compiling and releasing mods much easier. It uses Docker, so you don’t need the .NET SDK installed locally—this keeps your system clean. For example, you can download an open-source mod’s code and compile it right away.

Regarding Visual Studio: it’s definitely a powerful and comprehensive IDE, especially for beginners. I do have a slight bias—I find it a bit too heavy on older machines, so I lean towards lighter options like VS Code. The trade-off is that with VS Code, you gain more control (e.g., using `dotnet build` commands) but lose the one-click compilation convenience of Visual Studio. This script aims to bridge that gap: it offers easy compilation without requiring the .NET SDK or any IDE, using only Docker, which I find keeps things cleaner.

The script works with SMAPI. I use it to make SMAPI-based C# mods myself. It mounts your game folder to get the necessary SMAPI and game files when compiling.

On a related note, I’ve seen some community discussion about AI-made mods and concerns over quality. Personally, I’m open to AI-assisted modding. As a coder who mostly works with other languages, AI helps me tweak existing mod code faster, and with this script, I can quickly compile and release updates. It’s all about boosting productivity while keeping things accessible.
 

SomeoneEls

Farmer
Nice! I was thinking about this actually overnight a lot, and I think this could work wonders with linux and mac users since visual studio is windows locked to my knowledge.
 
Top