Hi fellow devs,
I have written some projects using the MonoGame NuGets. I added some content like shaders/effect files, 3D models, fonts and created a new NuGet from it.
Now I want to consume that NuGet in another project. Unfortunately the other project throws an exception since it cannot find the Content
directory. That makes sense, since I thought that would be included in the NuGet and looked up there.
My code inside the nuget does the following:
- It tries to get an effect file from the
Content
directory
- It fails because this would be the content directory of the original project from which the nuget was packed.
So whats the correct way to build a NuGet using MonoGame and still deliver some basic assets with it (like a simple 3D doll or some pre-made shader files).
TL;DR
- Project with MonoGame
- Has Content with
*.fx
and *.obj
files
- Content files are used by project
- project packed as NuGet
- NuGet used in other project
- Content not available
Hope you can help. Thanks for having a look : )
Cheers,
Georg
When I understood correctly you have a NuGet project which inlcudes some MonoGame content files and you want to use that NuGet project in a different MonoGame project which should consume the content files from the mentioned NuGet project.
There a several ways of doing this. You could for example:
- Include the content files in your .nuspec and output it accordingly
- Use a ResourceContentManager
In my MonoGame.Forms project i’m doing both.
- .nuspec
-
ResourceContentManager | Loading Data
I hope this helps.
Cheers,
:: Marcel
Yeah, I’ve done this. Nuget will drop the file in the Content folder, but you’ll still need to manually add it to the .mgcb using the Content Pipeline tool. Here’s an example of a shader added in a nuget package:
https://github.com/dmanning23/RenderBuddy/blob/master/RenderBuddy/RenderBuddy.nuspec
Cheers!
Yeah, that’s right.
If possible I would pre-compile the content and directly add the XNB files to the NuGet project. Then it’s easier to load the content in a different project.
If you don’t want to manually add the files to the .mgcb later you could also do it by generating a content response file programmatically (it’s just a simple .txt file which works like the .mgcb) and then use the MGCB.exe to automatically build the raw content, by running a small batch file like this:
@echo off
cd /d %~d0%~p0
call MGCB.exe /@:Content.txt
echo.
BTW: I created the project MonoGame.RuntimeBuilder to make runtime compilation available. Feel free to check it out.
Thanks for your hints. I’ll be sure to try them later.
Hi devs,
I actually ended up doing it the same way MonoGame ships the builtin effects.