Content does not get build from a MG project referencing a MG GameLibrary project

I have a WindowsDX project which references a MonoGame GameLibrary project. The GameLibrary Project has Content which I would like to get build and copied so that I can use it in the WindowsDX project. What is the mechanism that triggers the content build? What should I check to find out what is wrong / missing?


I’ve done this before in some of my projects such as this one: MGUI . I don’t know exactly what made it work, it kind of just worked first try, but here’s all my suggestions:

  • In your GAMELIBTEST7.WindowsDX project, add a Content folder. Then in Visual Studio’s Solution Explorer, right-click the Content folder, ‘Add’ → ‘Existing Item’, and browse for GAMELIBTEST7.GameLibrary\Content\Content.mgcb. In the bottom-right corner of the file browser dialog, click the dropdown on the ‘Add’ button and choose ‘Add as link’.

  • In your GAMELIBTEST7.WindowsDX project, add the ‘MonoGame.Content.Builder.Task’ nuget package

  • I assume you already have your Project Dependencies set up such that GAMELIBTEST7.GameLibrary is a dependency of GAMELIBTEST7.WindowsDX

  • You might also need to add a .mgcb to your GAMELIBTEST7.WindowsDX project, even though it won’t have any content. (Just use the MGCB tool to create a .mgcb file, then in Visual Studio right-click the Content folder, ‘Add’ → ‘Existing Item’ and browse for it.) Though this could cause problems if the .mgcb file has the same name (“Content.mgcb”) in your other project. So you might want to rename GAMELIBTEST7.GameLibrary\Content\Content.mgcb to something like GAMELIBTEST7.GameLibrary\Content\GAMELIBTEST7.GameLibrary.Content.mgcb

If you take a look at my repository you’ll see that the MGUI.Core project has an MGUI.Core.Content.mgcb file. Then in MGUI.Samples project, I added a link to MGUI.Core.Content.mgcb

    <MonoGameContentReference Include="..\MGUI.Core\Content\MGUI.Core.Content.mgcb" Link="Content\MGUI.Core.Content.mgcb" />

And all of my projects reference MonoGame.Content.Builder.Task

<PackageReference Include="MonoGame.Content.Builder.Task" Version="" />

Forgot to mentiooin that I am testing with but not sure if that makes a difference here?

Here is another screenshot showing more info for the dependency setup of the projects:

I tried one thing, I added the content builder task to the game library project.

It is then building the content but it throws an error saying the content has been build for another platform?

I think this is not working and having the content builder task in the game library is not what is needed here. See this is an old setup, where I can load content from the netstandard library project in MG3.8 without having the content builder task nuget in the net standard project itself:

So I assume the content builder task will check the dependencies and build content from those as well automatically? But for some reason it is not working in my case.

Ok I checked the csproj files and you are right it was necessary to add a link to the content mgcb file to the WindowsDX project. So I added this to the file and deleted the content builder task from the game library again:

<MonoGameContentReference Include="..\GAMELIBTEST7.GameLibrary\Content\Content.mgcb" />

Thank you!

Did you add that reference as a link? If not, then I think it would just be a copy from the moment that you added the reference, rather than dynamically updating whenever you modify you GameLibrary project’s content. Not sure though.

    <MonoGameContentReference Include="..\GAMELIBTEST7.GameLibrary\Content\Content.mgcb" 
                              Link="Content\GameLibrary.Content.mgcb" />

Good catch. So when using Visual Studio there are two options afaik. First is adding it not as link, which is then effectively a copy from that moment of the original file and it will not update dynamically then as you said. If you add the file as link, then it shows up inside Visual Studio with a tiny arrow and it just points to the original file.

I used the third option by not using Visual Studio but editing the csproj by hand: ommiting the link part seems to behave like adding the file as link but it will just not show up inside Visual Studio in the solution explorer. So I think you can use the link part to tell Visual Studio where you want the linked mgcb file to show up in the DirectX project in my case. I think for now I don’t need the linked mgcb file to show up since I can always start the original one by clicking the file in the game library project.