Problems with pipeline content and spritefonts in Monogame 3.6 (Mac OS High Sierra)

Morning everyone!
I’ve set up my new Mac to work with Monogame 3.6, but I’m having problems with Visual Studio getting the font.
I’ve rebuilt many times now the Content.mgbc with a spritefont on it, but at the moment of running the code, I get an “Microsoft.Xna.Framework.Content.ContentLoadException” “The content file was not found.”.
Is the pipeline tool not building the package correcty or something like that? (I was trying to set up an Arial font, so nothing strange).
Thanks for your time!

EDIT : https://stackoverflow.com/questions/48327690/spritefont-error-in-monogame-on-macos-microsoft-xna-framework-content-contentlo
Also tried what they were talking in the solution, about downloading 3.7 and use the other pipeline tool, but to no avail.

I don’t think your problem is related to the SpriteFont on Mac issue from 3.6. My guess is your template isn’t set up correctly (if you are using a template).

Let me demistify the build/load process for content. There’s a little magic happening that causes a lot of people to not understand what the pipeline tool does exactly and what’s expected by the runtime. In what follows all paths are relative to the project root.

The Pipeline Tool builds asset files into .xnb files. It outputs them in a local bin folder. E.g. Content/bin for the default Content/Content.mgcb response file. The Pipeline Tool works as a standalone application and does not integrate with your .csproj in any way.

To get the full path to an .xnb file, the ContentManager.Load method combines the working directory, ContentManager.RootDirectory, the specified path and the .xnb extension. E.g. for “asset” and with the default RootDirectory, “Content”, it will look at “bin/Debug/Content/asset.xnb”. If the file is not there it will throw a ContentLoadException and it’s by far the most common cause for that exception. The inner exception will give you the path the ContentManager searched at.

The magic part is how MonoGame builds the .mgcb file and gets the .xnb files from the local .mgcb bin folder to your project bin folder. This is done with a custom build action called MonoGameContentReference. In the templates this is the build action for the Content/Content.mgcb file. A build action is triggered whenever you build the project. The MonoGameContentReference build action

  1. Builds the content to the local bin folder (if it needs rebuilding)
  2. Copies content from that local bin folder to the project bin folder combined with the same relative path as the directory with the .mgcb file has to your project root. So for the default .mgcb file “Content/Content.mgcb” it’s content will be copied to bin/Debug/Content/(filename wo extension).xnb

To use this build action you must import a .targets file that comes with MonoGame in your .csproj. if you do not set this build action you have to copy the .xnb files to the right location manually (or provide your own automated system for it). If you build content from the pipeline tool, it will only output to the local bin folder and the ContentManager won’t be able to find the .xnb’s at runtime.

1 Like

Oh my, tried to copy what you have said and worked! (I mean, copying the generated file to /Debug).

Also, knowing that now (and thanks for that great explanation!) , I saw the problem.
Pipeline was targeting “Windows” as platform instead of “DesktopGL” , now it is working!

Thanks again for your help! Now I can continue working with this!

1 Like