MonoGame's cross-platform development capabilities are no longer as lacking as they used be, but they still have some odd issues every once and a while.

In particular, when working on Linux distros such as Ubuntu, you will find that MonoGame lacks an installer. They offer compiled binaries and a working version of the Pipeline tool. It works fine, but you can sometimes get peculiar errors when working with MonoGame.

Specifically that it is missing the .targets file used to build the MGCB file included in your project, if you have one.

To fix this, you can drop a copy of this file into the folder that XBuild (Mono's equivalent to MSBuild) uses to hold these target files. Here's a copy of the rules used to find such files:

MSBuild extensions are usually installed in $(MSBuildExtensionsPath), which XBuild resolves to $prefix/lib/mono/xbuild. When used in Import, like:

<Import Project="$(MSBuildExtensionsPath)\TestTargets.targets"/>

xbuild tries various values for the msbuild property $(MSBuildExtensionsPath), in order:

  1. Paths specified in the environment variable $MSBuildExtensionsPath.
  2. /Library/Frameworks/Mono.framework/External/xbuild on Mac OSX.
  3. $XDG_CONFIG_HOME/xbuild/tasks (or Environment.SpecialFolder.ApplicationData)
  4. $prefix/lib/mono/xbuild (default location)

I found mine in the third option, $XDG_CONFIG_HOME/xbuild/tasks (Note: you may have to create the tasks sub-folder). To locate your XDG_CONFIG_HOME, just paste:

printenv | grep XDG_CONFIG_HOME

into a bash shell. Then, drop the MonoGame.Content.Builder.targets file from earlier into your $(MSBuildExtensionsPath)\MonoGame\v3.0\ folder, creating the sub-folders if they do not exist. I found my MSBuildExtensionsPath at /home/user/.config/xbuild/, though yours may differ.

Happy coding!

Benjamin Ward


This guest post was provided by Benjamin Ward (@TheProgramm3r) who is helping with the MonoGame.Extended library.