I live in the Pacific Northwest region of the United States, and this past week, we’ve had a patch of bad weather. There’s nothing like a bit of nature to put you in your place — and for the past few days, my place has been at home, staring out the window at the thick blanket of snow covering my neighborhood. Even with 4-wheel drive, my driveway is too steep for my truck to climb without chains. That’s a great excuse to do nothing but sit around and play Xbox 360 games all day, but my console finally succumbed to a general hardware failure… Also known as the Red Ring of Death.
Without an Xbox 360 to distract me, and without the ability to go out and get a new one, I had to find something else to do. I considered writing a blog entry, but I didn’t know what to write about. I did something else instead, and since it’s a few days later now, I’m going to write about that.
A while back, I explained how to create custom templates for XNA Game Studio 2.0. I wrote that post because the built-in Export Template command in Visual Studio doesn’t work with Game Studio projects, and it isn’t extensible so we can’t modify it to work. So this weekend, I wrote a utility of my own that will turn your game projects into game templates.
How to Use the Template Exporter
Find a suitable directory on your machine, and extract all the files from the .zip file. One is an EXE named TemplateExporter, and the others should be supporting files (eg, documentation or license). Keep them together. To create a custom template, all you need to do is create a game project in XNA Game Studio, give it an appropriate name, and then run templateexporter.exe on the project file (.csproj).
To make things super easy, here’s how to create a menu command in VS to export the Game Template:
- Start Visual Studio or Visual C# Express, whichever one you are using with XNA Game Studio.
- On the Tools menu, select External Tools…
- Click Add
- In the title field, type Export Game Template…
- In the command field, hit the browse button (…), select templateexporter.exe, and click OK.
- In the arguments field, type the following (including quotes) "$(ProjectDir)$(ProjectFileName)"
- Check the box labeled, "Use output window"
- Click OK
That’s it. Now all you need to do is create a game project and run Tools->Export Game Template…
Where the Templates Go
If everything works out, you’ll be able to create a project from your template by looking in the My Templates section of the New Project dialog.
A Few Words of Caution
I haven’t really tested this utility much. After it creates the template, it opens up Explorer at the folder where the template was created. This is so you know where it is, since I’m guessing most people will end up sharing the templates. Templates are .zip files, and the name is based on the name of the project you are exporting. If the name already exists, the template will be created with a random suffix to avoid overwriting anything. It’s up to you to manage your templates.
I don’t have support for creating a template description or customizing the icon. You can do those things yourself pretty easily by editing the .vstemplate file inside the template’s .zip file. That is, extract all the files, edit the .vstemplate file, then zip all the files back up again. Make sure you zip up only the files, not the folder – the .zip file has to contain the .vstemplate file in its root folder.
Keep in mind that when you run the menu command, the arguments specify the current project based on the active document or Solution Explorer selection. Please note that game projects contain nested content projects… which means you can accidentally export just the content project if you have a content item selected when you run the command. If you export just the content without a game or library project, it won’t do anything useful.
This exporter utility was written for XNA Game Studio 3.0, but it will probably work with XNA Game Studio 2.0 projects as well (but I haven’t tried it, and don’t recommend it). If you don’t have XNA Game Studio 3.0 at all, the templates should end up in your Documents folder instead.
[Note (Jan. 11, 2009): I've uploaded a new version of the template exporter and modified this post to delete the reference to a DLL that is no longer included (or required) in the ZIP file.]