.Net, Azure and occasionally gamedev

Monogame on .Net Core with native AOT compilation

2018/08/25

Over the years I have spent many hours working with XNA/Monogame. As a percentage of all my time writing software as a hobby it probably has to be 25% or more.

It's an overall fantastic, well thought-out framework that sits perfectly between very low level APIs such as SharpDX and high level platforms such as Unity and Unreal.

XNA also came out (for free) at a time when a lot of those editors had very high entry requirements (initial license fees, dev slot fees, ..).

I only really started with XNA 3.0 but being able to develop for pc, Xbox and Phones at the same was working really well back then.

After more high level platforms emerged and also became affordable for indie developers I tried a few of them but for my taste they where (and still are) too much removed from my idea of "making games" (which is probably more "writing rendering software and frameworks" than anything else).

I just couldn't get into the whole "write a tiny script and click together predefined elements to make a game" workflow and I feel much more at home in XNA and now Monogame which has replaced XNA (since XNA is no longer maintained).

I'd much rather spend 20 hours to write my own mesh generation component and come away with having learned how to (or how not to) write the code underneath the surface.

My refusal to use such high level editors probably also explains why I have finished less than 10 games when I have easily started on 100+ different ideas.

There's no denying that using Monogame means you have to write a lot more code compared to Unity and that the Monogame API doesn't perfectly fit the idioms of the newer generation rendering APIs (Vulkan, DX11, ..) as Monogame is based around the DX9 implementation idiom and sort of shoehorns DX11 and OpenGL support into it.

But hey, I'm having fun down in the graphics layer, writing frameworks and never quite finishing anything.

In recent years I have spent less and less time with Monogame (and game development in general) however I decided to come back to give it another try.

Since I'm working quite a lot with .Net Standard and .Net Core I wanted to see if I could at least use .Net Standard libraries with Monogame. To my surprise there even is an experimental .Net Core branch of Monogame that I got working both on Windows and Linux!

Digging further I found this which allows you to compile your .Net Core based Monogame project into a native binary which could improve performance a bit more (not that C# is too slow, it's quite fast already).

I got the AOT compilation working on a basic hello world sample, but unfortunately all my old samples didn't work correctly with it when I tried to compare performance.

Without the AOT compilation they where working but with it my games start and instantly crash - I assume because I'm using unsupported reflection somewhere or because it's all very early stages (after all you have to get the AOT compiler alpha package from a separate feed).

Still having Monogame running on .Net Core (with potential "official support" in one of the upcoming releases) is already exciting.

Time to dust of my graphics knowledge and write some shader and rendering code.

tagged as .Net Core and Monogame