Editing The Default XNA Game Studio Project Templates
During a recent conversation in #xna, one n00b was whining about the default clear color in XNA Game Studio. Ridiculous, right? Who doesn’t love CornflowerBlue? Apparently this guy.
Anyway, I thought I’d take a quick spin at showing how you can edit the default XNA Game Studio project templates to suit your needs. We’re going to first make our changes and then I’ll show you two methods (the “right” way and the “wrong” way) to install the templates. The “right” way is to install them as a custom template in your user directory. The “wrong” way is to install them back into the main Visual Studio installation directory (thus overriding the original project templates).
To get started we need to locate and backup our existing project templates and project template cache. Visual Studio creates a cache of your project templates which is what it actually uses when creating your project. So both of these elements are important. We’re going to back them up just in case we mess something up and want to restore things back to normal.
Since I’m using the XNA Game Studio 3.0 beta, I’ll navigate into %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates\CSharp\XNA Game Studio 3.0. This is where the templates themselves reside. All Visual Studio templates are represented as ZIP files with special XML files inside that describe the content held. We are going to modify all three game projects, so create a folder somewhere (on the desktop is fine) and copy the XnaWindowsGame-v3.zip, XnaXbox360Game-v3.zip, and XnaZuneGame-v3.zip files to this directory.
If we’re doing this the “wrong” way, now we need to copy the caches for each of these ZIP files as well. Head back up to %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE and then navigate to the ProjectTemplatesCache\CSharp|XNA Game Studio 3.0 directory. Since these folders have the same names as the ZIP files themselves, create another directory next to your other one and copy the three folders with the same names as the projects to this folder.
We now have a proper back-up just in case, so let’s start with the editing. Unzip the three project template ZIP files into separate directories. Head into any of the three directories and you’ll see a bunch of files that should look fairly familiar.
What you need to do now is fairly simple: edit the files. (Note: You might have to make the files not read-only first. Right click on the file and select Properties. Then uncheck the read-only box.) You’ll notice the files have some strange characters and strings in them. These are Template Parameters used to generate the file. For the sake of this article, we’re simply going to head into Game1.cs, head to the Draw method, and change the color from CornflowerBlue, the greatest default color ever, to something our n00b friend will like more: Purple. Simply change this line:
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
to
graphics.GraphicsDevice.Clear(Color.Purple);
and you’re all set.
We’re all done editing our templates so we need to finish this off. First copy the Game1.cs file you just edited into the other two folders. This ensures that all templates are using the same default Game1 class. Next, select all the files in a single template directory and add those files to a ZIP file. Make sure this ZIP file has the same name as the files we copied earlier. Also make sure your ZIP file does not include the actually directory (i.e. all the files should be in the root of the ZIP file). Next repeat this for the other two templates.
To do this the “right” way by simply not putting these ZIP files back into the Visual Studio installation folder. Simply go into your documents folder and then navigate into Visual Studio 2008\Templates\ProjectTemplates\Visual C#\XNA Game Studio 3.0 (make the folder if it doesn’t exist). Then place the ZIP files there. If you go this route, simply skip down to the end.
To do this the “wrong” way, next we’ll be adding the templates back to Visual Studio. Navigate back to %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates\CSharp\XNA Game Studio 3.0 and drop those three ZIP files back in there.
The last thing we have to, if doing this the “wrong” way, is regenerate the template cache. First make sure no instances of Visual Studio are running, then open up the Visual Studio 2008 Command Prompt. You can find this by going into your Start Menu under Programs->Microsoft Visual Studio 2008->Tools. If you are on Vista, make sure you right click and select Run as Administrator. In the command prompt, enter the following command:
devenv.exe /InstallVSTemplates
and press return. The prompt usually returns immediately (as indicated by a flashing cursor on a new line), but there is a background process running at this point. Give it a good thirty seconds or so to complete before trying to create a project.
Once the cache is recreated, the templates are ready for use. Open up Visual Studio 2008 and create a new Windows game. If you chose to do this the “right” way, you will want to look in the “My Templates” area of the templates screen and choose the projects there. Run it and marvel at your ugly, I mean beautiful, purple window.
Possibly Related Posts
(Automatically Generated)New Minimalist Templates
Pong in F# with XNA Game Studio
Visual Studio 2010, XNA, and you
XNA Game Studio 3.0 Dated for October 30th
New 3.0 Minimalist Templates
