This guide assumes:
- Visual Studio 2010 Professional
- XNA Game Studio 4.0
- Users will be Windows
This is the second article about building an XNA game installer when you are ready to distribute your game to the masses. In the first part, I described how to use the convenient ClickOnce option to build a relatively simple and non-customizable deployment package. If the ClickOnce option is too restrictive for you or simply does not meet your needs then you should refer to this article about using a Setup Project to create a more customizable installation package.
As with most things in life, the Setup Project is not a perfect solution to packaging up and distributing your game. What I find extremely annoying and shortsighted on Microsoft’s part is that the Setup Project will not automatically detect your game content like ClickOnce does. I want to be clear that, in this context, “content” is referring to your compiled content by the Content Pipeline (textures, sounds, other files) and not the “content” of your project as a whole. I will explain how to force the Setup Project to use your game content. Be warned: it is tedious and annoying, but it works..
- Open your game solution
- Right click solution -> Add -> New Project…
- Other Project Types -> Setup and Deployment -> Visual Studio Installer -> Setup Project
- Right click the setup project -> Properties
- Change the “Configuration” drop down to whatever configuration you want the setup to use (debug/release/etc)
- Click “prerequisites”
- Make sure these are checked:
- Microsoft .NET Framework 4 Client Profile (x86 and x64)
- Microsoft XNA Framework Redistributable 4.0
- Windows Installer 3.1
- Right click the setup project -> View -> File System
- In the “Application Folder”, right click -> Add -> Project Output
- Change the “Project” drop down to the main game project
- Click “Primary” output in the list box
- Choose the configuration for which you want to include the output (debug/release/etc)
- Repeat steps 9-12 for any other projects that you need to include in the output (custom libraries)
- NOTE: Do note include output from content pipeline extension projects because the content pipeline it is unavailable at run time
You just created a setup project, told it which prerequisites are needed for your game to work, and finally told it which build output you want to include in the installer. You can arrange the “File System” folders to how you see fit for your application folder hierarchy. For example, you should see options to include files in the User’s Desktop or the User’s Programs Menu in case you want to include shortcuts. Be careful not to abuse this though, because the user will not be happy if you dump 500 files on their desktop!
While that was relatively painless, all is not well in setup project land. For some reason there is no way to have the setup project automatically find your compiled content in .xnb format after the content pipeline has imported and processed your content files. You can include the “Project Output” of the content project, but that will not do anything useful, so do not bother!
The only way that I have been able to successfully include the .xnb files in the setup project is to manually create the folder structure of my content and include the files one-by-one similar to how we added the project output in steps 9-12 above. For example, the output of your content project could look like the following after your project is built:
You will need to go to the “Application Folder” similar to step 8 from above.
- Create the folder structure exactly as your content project is setup
- Go to each folder one-by-one and Add -> File…
- For example, for the above sample, I would navigate to Content/Fonts and add Main.xnb
- Then I would go to Content/Sounds and add Death.xnb and Shoot.xnb (you can multi-select files at least)
Note that this process assumes you have built your solution and generated the .xnb files prior to trying to add them to the setup project. This process is hideously tedious, but it gets the job done. It gets even worse when you have to remember to add new files to the setup project after you add them to your content project, because they are not automatically discovered!
There are a lot more options that Setup Projects provide to you. I cannot possibly go through them all here. I suggest you go to MSDN and read up more on how to tweak some things like Custom Actions, Launch Conditions, and other neat features. Make sure to change some of the Properties on the Setup Project like “Author”, “Manufacturer”, “Product Name” and “Version” so that the metadata is proper when the user installs your game.