MonoGame 3.8 Referencing MonoGame.Content.Builder.Task Locally

I’ve cloned the latest MonoGame repo and am trying to hook it up to a project I am working on.
I can build the MonoGame.Content.Builder.Task .csproj just fine, but when I try to reference it from my Universal Windows project by right-clicking References > Add Reference… and selecting the MonoGame.Content.Builder.Task project, I just get an error saying:

Unable to add a reference to project 'MonoGame.Content.Builder.Task'

In another project (a DesktopGL project) I can add the reference, but it doesn’t build content.

Upon looking at this project, it just seems to consist of a bunch of .targets and .props files.
The documentation I’m working through on Microsoft Docs about these types of files makes sense, but I’m not getting how this stuff gets referenced and uses when another projects takes this one as a dependency. There might be some NuGet packaging magic here that makes this different than other projects - so I’m hoping maybe someone can shed a little light on all of this and how to locally wire it all up?

Ultimately I really want to understand this so I bring in both the MonoGame projects and my own into a single solution, reference them up, and build them so I can debug and trace through all the code at once.

When you have a PackageReference, it automatically imports any props and targets files with the same name as the package. However I don’t believe the same is true of a ProjectReference. Instead of referencing the project, try adding a <Import Project=“...” /> for both the props and targets files.

1 Like

That definitely helped (and solved another question I had posted, thank you!).

I’ve since added Import tags to the 2 .targets and the .props file from the locally cloned repo folder
<Repo path>\MonoGame\Tools\MonoGame.Content.Builder.Task\

It looks like this (replace with your path):
<Import Project="<Repo path>\MonoGame\MonoGame\Tools\AppReference.targets" />
<Import Project="<Repo path>\MonoGame\MonoGame\Tools\MonoGame.Content.Builder.Task\MonoGame.Content.Builder.Task.props" />
<Import Project="<Repo path>\MonoGame\MonoGame\Tools\MonoGame.Content.Builder.Task\MonoGame.Content.Builder.Task.targets" />

However, now when I go to build my project, and the system knows it needs to build content, I get the following error:

The command "dotnet <Repo path>\MonoGame\MonoGame\Tools\MonoGame.Content.Builder.Task\\..\tools\netcoreapp3.1\any\mgcb.dll /quiet /@:"<Project Path>\MonoGameTest\Pong\Content\Content.mgcb" /platform:DesktopGL /outputDir:"<Project Path>/MonoGameTest/Pong/Content/bin/DesktopGL/Content" /intermediateDir:"<Project Path>/MonoGameTest/Pong/Content/obj/DesktopGL/Content" /workingDir:"<Project Path>/MonoGameTest/Pong/Content/"" exited with code 1.

I found the path of \\..\ to be weird. This is being set in the MonoGame.Content.Builder.Tasks.props file, as the following line:

<MGCBPath Condition="'$(MGCBPath)' == ''">$(MSBuildThisFileDirectory)\..\tools\netcoreapp3.1\any\mgcb.dll</MGCBPath>

Does this… seem right? Is that a valid path?
I tried removing the \ after $(MSBuildThisFileDirectory) but it still didn’t work.

So I replaced the path entirely with the hard-coded path of my build mgcb.dll (which is totally different that the path eluded to here, oddly enough. My path ended up being:

<Repo path>\MonoGame\MonoGame\Tools\MonoGame.Content.Builder\obj\Debug\mgcb.dll

It now gives me this error output:

The command "dotnet <Repo path>\MonoGame\MonoGame\Tools\MonoGame.Content.Builder\obj\Debug\mgcb.dll /quiet /@:"<Project Path>\MonoGameTest\Pong\Content\Content.mgcb" /platform:WindowsStoreApp /outputDir:"<Project Path>/MonoGameTest/Pong/Content/bin/WindowsStoreApp/Content" /intermediateDir:"<Project Path>/MonoGameTest/Pong/Content/obj/WindowsStoreApp/Content" /workingDir:"<Project Path>/MonoGameTest/Pong/Content/"" exited with code -2147450749.

Any idea what this code is, or what I can do next to build this project’s content?
I can’t find the error code in any other Community post.

  1. The double slash wouldn’t be an issue. And the .., if you’re not familiar, means to go up one level to the parent folder. So yes that is a valid format.

  2. The default path $(MSBuildThisFileDirectory)\..\tools\netcoreapp3.1\any\mgcb.dll is where the file would be if it were packed into a NuGet package. You’re right that you should override it if you’re using a local reference.

  3. Never use anything from the obj folder. That’s for intermediate files that are being built and linked that won’t work on their own. Try using the path
    <Repo path>\Artifacts\MonoGame.Content.Builder\Debug\mgcb.dll

  1. Ok cool. I’m aware of the .. will go up a folder, but haven’t come across the double slash syntax. However, once I had determined something different happened when I hard-coded the entire path, I should have just tried replacing the right-half of the path with a relative path to the Artifacts folder. My bad on that.

  2. Makes sense on the NuGet side of things. I see now the AppReference.targets has a PackagePath with the tools\ path in it. I’m new to setting up projects for NuGet package output. I’m going through this Doc currently to try and get more up to speed:

  1. Thank you - yeah, should have never thought the obj folder as well. I see now too when editing the MonoGame.Content.Builder.csproj file the BaseOutputPath is set in that Artifacts folder


At this point I now see in my output that the content build is doing its thing. However after building (or skipping) the content files (it lists all of them) my build freezes, and after several minutes just fails out. I get no errors reported to go off of either. I’m trying to figure out what could be getting stuck, or even how I could just get some kind of error log of tracing on this. Any ideas?

Nothing comes to mind immediately. Do you have Detailed build logging? Can you share the final logs you see and what target it’s hanging on?