Running a Multi Platform Game on Linux

Hi,

I’ve been using Monogame 3.7 for a few years now but only targetting Windows DirectX. I’m now looking to use Monogame to it’s full potential and develop multi platform.

I use Visual Studio 2019 on Windows 10, I’ve got Monogame 3.8 up and running, and have a solution with a shared project containing my game core, and platform specific projects for WindowsDX, OpenGL and Android. I have just one MGCB that is shared by all.

This all works great, there is just one game core. It works fine on Windows 10 DX or OpenGL, fine on Android, but what I need help with is getting it going on Linux. I’m a bit of a Linux novice.

Currently I can only run Linux projects if I create them on the Linux machine using Visual Studio Code and run them from the IDE. I thought it would be possible to compile an OpenGL project on my Windows machine, copy it over to Linux (Ubuntu 20.4) and just run it. I don’t really want to have to recreate the project on a Linux machine and recompile it there, it feels like it’s defeating the object of one code base for multiple platforms.

I guess the question is, am I missing the point here? I can compile on Windows and deploy to Android, but I don’t seem to be able to deploy to Linux.

Hope someone can help me see the light!

Rich.

It’s already working – you need to install mono on Linux and then run your exe via mono.

1 Like

Ha, blimey, you’re absolutely right. So here’s a weird thing! I’ve just created a brand new Monogame 3.8 OpenGL test project. Compiled it on my Windows 10 machine, copied the binaries over to Linux. The executable is called OpenGLTest.exe, so in the terminal window I type…

mono OpenGLTest.exe

Error, file does not contain a valid CIL image.

Tried loads of stuff, reinstalled mono, dot net core, file executable permissions, tear out what’s left of my hair, then I’m just about to give up when I decide to try…

mono OpenGLTest.dll

…and it just works!

So is the .exe file used when running on Linux?

What is your project Target Framework? Is that version of the framework supported by the version of the Mono you have on Linux?

Yes, it’s NET Core 3.1. It must support it because it does work following Martenfur’s advice. My question now is why do I have to pass the .dll filename to Mono, rather than the .exe name? :slightly_smiling_face:

If you’re on .NET Core, publish your project with dotnet publish.

Example: dotnet publish -c Release -o ~/Desktop/MyGame --self-contained --runtime linux-x64

This creates a self-contained native executable. You can open the file by double-clicking or running it in a terminal window with ./MyGame in the same directory.

Thanks @Kimimaru, that’s really useful. I’ll try it later.

@Kimimaru thanks again. That was easy, and it just worked first time. As a Linux newbie, that doesn’t happen very often :laughing: