MGCB issues with relative paths to references

First of all, let me just say that I’m really impressed with the Pipeline tool so far. It’s a little clunky in some places but overall it works pretty well.

Anyway, I’ve been working on writing my own Content importers / processors / writers and readers. It’s all going reasonably well but I’ve run into a little problem.

When I create my DLL and reference it in the Pipeline I would like to use a relative path, the Content.mgcb file references section looks like this:

#-------------------------------- References --------------------------------#


The reason I would like to use relative paths is because I want the project to build out of source control regardless of what directory the project is checked out too. On my local machine and my latop (two different checkout paths) this seems to work okay.

But when my Team City build server tried to run MGCB.exe over the content file I got an error.

[Exec] "C:\Program Files (x86)\MSBuild\MonoGame\v3.0\Tools\MGCB.exe" /@:"C:\TeamCity\buildAgent\work\982dbc876ae2b3b0\Source\Sandbox\Content\Content.mgcb" /platform:Windows /outputDir:"C:\TeamCity\buildAgent\work\982dbc876ae2b3b0\Source\Sandbox\Content\bin\Windows" /intermediateDir:"C:\TeamCity\buildAgent\work\982dbc876ae2b3b0\Source\Sandbox\Content\obj\Windows" /quiet
[05:18:09][Exec] Failed to load assembly 'C:/TeamCity/buildAgent/work/982dbc876ae2b3b0/Source/MonoGame.Extended.Content.Pipeline/bin/Debug/MonoGame.Extended.Content.Pipeline.dll': Could not load file or assembly 'file:///C:\TeamCity\buildAgent\work\982dbc876ae2b3b0\Source\MonoGame.Extended.Content.Pipeline\bin\Debug\MonoGame.Extended.Content.Pipeline.dll' or one of its dependencies. The system cannot find the file specified.

I couldn’t really find any documentation on this topic, so I assumed the path is relative to the location of the Content.mgcb file. It seems to work on my local machine, but that could be a coincidence.

So I’m wondering if this is a bug, or if there’s some sort of workaround? In my opinion, it makes sense for MGCB.exe to consider the folder that contains the Content.mgcb file as the working directory by default. Otherwise, it’s a unclear how one would use relative paths?


That’s correct in my experience. The most likely problem is that your pipeline DLL (or one of it’s depencies) is not being built before the MGCB call. That’s could be why it works on your other machines - ie you’ve previously built everything. You could try deleting all bin folders and building on your local machines with the same process used on the TeamCity server to check my theory.

Good thinking @Aranda

There actually turned out to be 2 problems. I’ll write up the solution here for anyone else that might be having similar issues in the future.

Problem 1: Project dependedencies

The first was that the project containing the Content.mgcb file didn’t depend on the MonoGame.Extended.Content.Pipeline.dll project. That makes sense because it doesn’t reference it.

The solution was to manually set the Sandbox project to depend on the MonoGame.Extended.Content.Pipeline project. Visual Studio has an option to set project dependencies by right clicking the project.

Problem 2: Debug vs Release

The second problem was that I was building a Debug build on my local machine and a Release build on the build server.

Obviously the issue here is that the reference path is hard coded to the Debug folder.


I considered changing the output path of the MonoGame.Extended.Content.Pipeline project to always output in a known folder but in the end I just changed the build server to build Debug builds instead. Not ideal but it’ll do for now.

Maybe some changes could be made to the Pipeline tool to handle this kind of situation in the future, like the way Visual Studio has macros.


Thanks for your help :smile:

Ah yes of course, the Project Dependencies… that makes sense.

Regarding Debug vs Release, you may be able to use the $(Configuration) macro. Apparently $(Platform) works, so I imagine it will:

The ($Configuration) macro didn’t seem to work. I also tried $(ConfigurationName).

However, I did write a tutorial on how to create custom importers with the MonoGame Pipeline. Hopefully someone else will find it helpful.