Best practices for including assets in class library?

I’m working on a text rendering library and in order to make it easier to add to a project I am including the shader in the dll file.

What I do right now is this:

  • I use MGCB to manually build the shader for both WindowsDX and DesktopGL
  • I include those two files in my project as embedded resources
  • At runtime I save the appropriate version of the shader to a temporary file and load it with ContentManager.
  • I delete the temp file.

As far as I can tell there’s no way to load a shader from a stream (or anything else using ContentManager), which is why I save to a temp file.

I’d like to know if any of this could be done in a simpler/better way. In particular it’d be nice if I could edit the shader and then not have to manually build it.

I figured out how to use build events and now my shader automatically gets built and copied to the project folder.

How did you get it to work?

1 Like

Which part do you mean? The build event?
In my project properties I wrote this in the pre-build event field

mgcb content/WinDx.mgcb
copy Content\bin\content\Shapes.xnb ShapesWinDX.xnb /y
mgcb content/GL.mgcb
copy Content\bin\content\Shapes.xnb ShapesDesktopGL.xnb /y

I also put this in the project file to make it always rebuild the shader