Setting up MonoDevelop on Ubuntu for SMAPI Development

As with all things Linux, you occasionally run into a quirk or issue that is either caused by the project not primarily being developed or maintained for Linux, or more directly due to a Linux oddity. Today I'll run through the steps I took to get MonoDevelop set up correctly for SMAPI and SMAPI Mod development.

As of the posting of this article I am running Ubuntu 19.10, so the commands in this article are specific to this version. Similar steps should work for related versions of Ubuntu like 19.04 and the just-released 20.04, but you'll have to substitute version-specific commands and URLs where necessary.

Step 1: Install MonoDevelop

As of this writing the Mono project does not yet have repositories specific for newer versions of Ubuntu (neither 19.x or 20.x), so we'll use the 18.04 repository instead. I'm guessing they'll end up creating a new repository for 20.04 sooner or later, but until then this will work.

Before you follow this step, please head over to the MonoDevelop download page and check if they have since added new repositories for your specific version of Ubuntu.
sudo apt install apt-transport-https dirmngr
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb https://download.mono-project.com/repo/ubuntu vs-bionic main" | sudo tee /etc/apt/sources.list.d/mono-official-vs.list
sudo apt update

With the repository added you can now install MonoDevelop in the usual way:

sudo apt-get install monodevelop

Step 2: Install the .NET Core SDK

If you're looking to also work with or just compile SMAPI, you'll need to install this too.

Microsoft has their usual approach here of a slightly less traditional installation method, so let's follow the steps as they recommend:

sudo apt install apt-transport-https
wget https://packages.microsoft.com/config/ubuntu/19.10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt update
sudo apt install dotnet-sdk-3.1

I am not entirely sure when this went wrong, but it seems that at least more recent versions of MonoDevelop (I am running 7.8.4 at the time of posting this article) have an issue where it has a hard-coded reference to mono64 even though this does not exist (anymore?). This might be an oopsy related to the macOS version, but regardless of why this happened, the fix is easy for us; We just need to create a symlink that points to the correct mono binary and we're good to go.

Note: As files in the /usr/bin directory are owned by root, we need to sudo the following command.
sudo ln -s /usr/bin/mono /usr/bin/mono64

Ready to develop SMAPI Mods

You should now be able to start developing SMAPI Mods. I highly recommend you take a look at the official wiki page explaining how to get started with this if you're new to SMAPI Mod development.

The following steps are optional and only relevant to you depending on your specific goals or needs.

Optional: Specify your Stardew Valley installation directory

In case SMAPI or your Mod is having trouble finding Stardew Valley, or if perhaps you have multiple installations and want to target a specific one, you can specify a specific path to look for. This is globally set, so any mods you might be working on (or indeed SMAPI itself) will honor this setting.

Create a file called stardewvalley.targets in your home directory, and populate it with the following contents:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
     <GamePath>/path/to/your/sdv/folder/here</GamePath>
   </PropertyGroup>
</Project>

Optional: Launching Stardew Valley from your favorite Terminal

By default Stardew Valley for Linux launches using the file simply called StardewValley (no extension), which does some checking and defines a few things before launching. Mono actually throws a hissy fit if TERM is not set to xterm, which this script takes care of too. When you install a pre-built version of SMAPI, it comes with a replacement of this file that does the same thing but launches SDV with SMAPI instead.

If you want don't want to deal with these scripts or just want to launch SDV from a specific Terminal window without it opening additional ones, you can achieve this quite easily. All you need to do is make sure that the aforementioned value is set either globally or when you launch the game, and you can launch the game like so:

TERM=xterm ./StardewModdingAPI.bin.x86_64

Optional: Check out & build SMAPI

If you're looking to develop SMAPI itself or just want to build it locally, you can now download the SMAPI source code and load it up in MonoDevelop.

git clone git@github.com:Pathoschild/SMAPI.git

Open MonoDevelop and browse to SMAPI/src/SMAPI.sln and open this solution file. MonoDevelop will automatically start downloading and installing the packages SMAPI uses, which may take a while depending on your internet connection. Once done you can try to build SMAPI and see if it works for you. If all went well, a basic build command should work now, but using the debugging features won't, which seems to be a known limitation for SMAPI development.

If you have not previously installed a pre-built version of SMAPI, you might have to manually create a copy of the Stardew Valley binary. Head on over to the directory where Stardew Valley is installed, and create a copy of the binary:

cp StardewValley.bin.x86_64 StardewModdingAPI.bin.x86_64

SMAPI normally also comes with a replacement version of the StardewValley launch script. If you want to copy it in, you can find it at src/SMAPI.Installer/unix-launcher.sh in the repository. The official manual installation guide of SMAPI says you should rename the original StardewValley to StardewValley-original and then copy this file in place and rename it to StardewValley.

I personally prefer to launch the game directly from Terminal as I described in the previous section above though, but by having this file in place you also ensure you can play with SMAPI when launching the game from Steam for example.

Closing thoughts

I quite like MonoDevelop, it feels much faster than Visual Studio did under macOS. I am not entirely sure if this is purely because of MonoDevelop being faster or if it's because of how it works under Ubuntu, but either way I'm glad it runs as fast as it does. It is unfortunate that debugging doesn't work, but this issue exists under macOS too. It just seems like debugging SMAPI-related work is only really possible under Windows currently. Perhaps someone will one day be able to find a solution to that. Until then though, just build SMAPI or your mod (F7 by default), and (re-)launch Stardew Valley. I personally recommend using the Skip Intro mod as it really helps speed things up.