Is it possible to pack all the little .xnb files into one big file? Given the level of abstraction of the XNA Framework I though this would come out of the box but I can't find any well integrated solution.

So far the best candidate is XnaZip but in addition to having to compile the resources in a post-build event, and a little trouble porting the game to XBOX I have to rename all the references to resources I have already implemented.

  • \$\begingroup\$ Why do you have to rename references to your resources? After answering your question, I had a cursory glance at XnaZip; it seems like it should be a drop-in replacement -- aside from the missing System.IO.Compression namespace. \$\endgroup\$ Feb 16, 2011 at 12:58
  • \$\begingroup\$ In the readme of the XnaZip project it says: 'After that you can load your objects like this: Texture2D earth = content.Load<Texture2d>(ResourceId.Earth);' But now that you mention maybe I misinterpreted it and means 'you may' instead of 'you have to'. I will give it a try. \$\endgroup\$
    – Cristian T
    Feb 16, 2011 at 14:06
  • \$\begingroup\$ Why do you want to pack these files together? \$\endgroup\$ Jan 5, 2012 at 22:14
  • \$\begingroup\$ for easier distribution when you have tons of files and to hide internal resource names from plain sight \$\endgroup\$
    – Cristian T
    Jan 10, 2012 at 10:39
  • \$\begingroup\$ @PrinceCharles also keep in mind that copying one big file is much faster than copying many smaller ones (especially off of optical media). \$\endgroup\$ Feb 16, 2012 at 15:25

1 Answer 1


It's possible, but you either have to:

  • Find a library that does it for you, or
  • implement it yourself.

XNA lets you do the latter by deriving from the ContentManager class and replacing the OpenStream method; in fact, the documentation explicitly says:

protected virtual Stream OpenStream (string assetName)

Opens a stream for reading the specified asset. Derived classes can replace this to implement pack files or asset compression.

In the override version of OpenStream, one would simply return a compatible Stream that read the requested asset data from a pack file, rather than opening a FileStream from disk.

The tricky part is that you have to actually build the pack file yourself, incorporating the xnb files output via the content build pipeline. You could build a Content Pipeline Extension to do this, or find some other method, depending on what your goals are.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .