In the second WinForms sample there is a HTML readme file that describes how the application saves built content to a temporary directory and then deletes it when the program closes.
This is the important bit:
Depending on your application, you might prefer to always use the same temporary directory name, and never delete it. This will leave files lying around on your hard drive. The content build process is incremental. If your program tries to load the same content files that were already built during a previous run, you will not need to carry out any actual processing work. This can speed up loading times for programs such as level editors that are likely to want to load the same files each time they start up.
It says that deleting the temporary directory "is handled by ContentBuilder.DeleteTempDirectory
, which is called by Dispose
". So simply find the call to DeleteTempDirectory
and remove it.
The readme file describes in more detail how the temporary directory is selected (and why). You could modify CreateTempDirectory
to suit your application better. For example if your editor has "level" files, you might want to save your built content (.xnb files) in a subdirectory with the same name, next to your level, so that your game can easily open the built content.
Once your files are being kept between sessions - all you have to do is reload them. The two obvious ways are to store a list of the files that are open, and reload it next session. Or simply open everything that is in your output directory:
Here is some rough code to do the latter (assuming no subdirectories):
string folder = @"C:\TemporaryXNAFilesOrWhatever";
List<Texture2D> textures = new List<Texture2D>();
ContentManager content = new ContentManager(serviceProvider, folder);
string[] files = Directory.GetFiles(folder, "*.xnb");
foreach(string file in files)
{
string assetName = Path.GetFileNameWithoutExtension(file);
textures.Add(content.Load<Texture2D>(assetName));
}