It is not easy to set up monogame dev on Mac. It officially supports mono + visual studio for mac + monogame extension. However, there were several issues:

  • monogame extension does not support the new VS for Mac 2019, but only vs4mac 2017 . However, the 2017 download isn't available from Microsoft anymore (I had to download it from here)
  • I cannot scaffold projects with "Monogame Mac Application" (error: "Exception has been thrown by the target of an invocation.")
  • I was able to scaffold "Monogame Windows Application" or "iPad/iOs", but I couldn't build and run the projects.

Monogame on .Net core on Mac

I was able to scaffold and run using this setup:

Now following this blog, firstly install the Monogame project template:

dotnet new -i "MonoGame.Template.CSharp"

In a working directory:

dotnet new mgdesktopgl

With the basic setup, you should be able to run the blank game with:

dotnet run

Now let's follow official guide to add a ball sprite to the canvas.

Add a content by opening the Monogame Pipeline tool, add the ball.png to the Content project. Then make changes accordingly to the guide.


Fix monogame freeimage issue:

The pipeline tool modifies Content.mgcb to include some msbuild operations for ball.png. Specifically, the TextureImporter. Under the hood, it interopts with libfreeimage.dylib, which by some monogame bug, isn't shipped with the monogame.content.builder nuget package. To fix this issue:

1
2
3
4
5
6
7
8
9
brew install freeimage

# find the installed `libfreeimage.dylib`:
brew ls freeimage | grep -e 'libfreeimage\..*\.dylib'

# link it into the MG builder build tool folder:
ln -s \
/usr/local/Cellar/freeimage/3.18.0/lib/libfreeimage.3.18.0.dylib \
~/.nuget/packages/monogame.content.builder/3.7.0.4/build/MGCB/build/libfreeimage.dylib

Now we are ready to build and run the game and see the ball image:

dotnet run

The complete working code is at https://github.com/kflu/monogame-setup

2020-01-31 Some more learnings (quick note)

Pipeline tool is just a GUI helping you to construct the Content.mgcb file. The content building actually happens at build time, the Content.mgcb file is actually the command line parameters for calling MGCB command. In this sense, the pipeline tool is not necessary - why I don't want to use it?

Problem 1: Pipeline tool crashed when adding reference

I try to add Tiled map to content - they require additonal reference assembly for MGCB to build. Pipeline can add reference. But it has a bug crashing when adding references.

Problem 2: Difficult to add dependencies of the reference manually in MGCB file

It's not easy to add reference to MGCB file. Because you not only add the reference, but also all its dependencies. Something like this:

/reference:PATH1/MonoGame.Extended.Content.Pipeline.dll
/reference:PATH2/MonoGame.Extended.dll
/reference:PATH3/MonoGame.Extended.Tiled.dll
/reference:PATH4/Newtonsoft.Json.dll

I don't know if Pipeline tool help you add all dependencies, if you add a reference assembly via Pipeline tool. But since it's broken I don't have this help. And manually figuring out all dependencies and type their physical paths are infeasible.

What I did was creating another .net core classlib (netstandard2.2). Adding the top level reference via dotnet add package .... Then dotnet publish. I got the reference assembly and its dependencies all flattened in the publish folder. Then I was add all of them as reference in MGCB file:

/reference:../../pipeline_libs/bin/Debug/netstandard2.0/publish/MonoGame.Extended.Content.Pipeline.dll
/reference:../../pipeline_libs/bin/Debug/netstandard2.0/publish/MonoGame.Extended.dll
/reference:../../pipeline_libs/bin/Debug/netstandard2.0/publish/MonoGame.Extended.Tiled.dll
/reference:../../pipeline_libs/bin/Debug/netstandard2.0/publish/Newtonsoft.Json.dll

Problem 3: relative paths between content files

The relative paths between the tiled map (tmx), tilesets (tsx), the raw assets (png) are inconsistent when they are copied or imported to the game project directory. So often dotnet build (or just mgcb) complained the file could not be found.

This is a process issue, I'd feel more comfortable once a pattern is found.

Problem 4: /build command with source & destination doesn't work

Form /build:<src>:<dest> doesn't work. While according to MGCB document, it should work. It says file path <src>:<desst> not found, as if it doesn't understand this syntax.