Attach .fx file to class lib, publish to nuget and load in game

How can I attach a .fx file or a .png to a class lib and then how can I load it in the projects using this lib.

I found an article on the microsoft xna pages but I dont understand it… :frowning:
Maybe someone here has done it and can tell me how to do it

Are you publishing the lib as a nuget package, or pulling it in as a git submodule or something?

I am publishing it as a nuget package

You can add a file to the “content” folder using the .nuspec file for your library.
The users of your lib will still have to manually add it to the content progrect using the MGCB though.

1 Like

My solution is easier to work with:

If you look in the Source folder, I have a Content folder with a .mgcb for the library. This gets included automatically in the projects that consume my library using the Apos.Shapes.props file.

In the csproj I have:

Since I include the .fx source code, it means it can be compiled for the various MonoGame platforms like DesktopGL or WindowsDX.

1 Like

Cleanest way how to do this is probably include effect byte code, not fx :slight_smile: use MGFXC to compile fx, include result, create custom derived Effect class by feeding byte array to constructor.

For details visit: MonoGame Effects Compiler (MGFXC) | MonoGame Documentation


I don’t think that would give you a cross platform effect byte code? Maybe OP doesn’t need cross platform though.

(With my library you get the right shader for the right platform at build time (If the shader is written correctly.).)

wow yeah that is much better :smiley:
I didn’t even know that was possible :+1:

Thanks for all the suggestions. I would consider all three sugesstions as a solution to my problem. :))
I am going to mark the first one as the solution just because it was the first suggestion