Microsoft XNA and Visual Studio Express have been my favorite game development tools since 2007. "ShockBall" (2008) was the first game I made using XNA, currently I am working on 3D action shooter called "Rebellion".

I always found answers to my questions on forums, web sites and blogs, and I would like to contribute by sharing some of my knowledge.

Monday, October 19, 2009

Distribute your XNA game on Windows

There are many ways to distribute your game on Windows platform, it all depends with whom would you like to share it.
If you would like to give it to your friend or someone from XNA community for testing, just make sure he/she has XNA installed. Build release version and compress content of the bin/x86/Release directory inside project root directory. You can also create package inside Visual Studio.
Games for Windows are usually installed on your PC via setup procedure. Installer makes sure system configuration meets the requirements, copies files from the package on the file system and installs all missing components. XNA games require following components to run: .NET framework, DirectX and XNA.
Ok, lets create installer for you new game. Build release version of the game in Visual studio, then download "Inno setup" installation builder and install it on your computer. "Inno setup" is free, easy to use and well documented.
Start Inno and create new script. If you choose to create empty script, just copy/paste all sections from this article into your script. If you made your script with wizard, manually add all missing directives from this article into your script.
I use some fictional names, like myXNAGame, and locations in the script. Replace them with actual information about you and your game. If you need any additional information about specific section or directive, just open help document and look under Setup script sections.

Setup section

Directives in this section define global settings used by installer. Setup directives are split into installer and compiler directives. Installer directives control operation of the setup program. Compiler directives specify compression, encryption, file name... of resulting setup file.

I will use only small set of directives in Setup section. Replace values of AppName and AppVerName directive with the name of your game and value of AppPublisher with your name or name of your company. If your game does not have its own website, you can remove AppPublisherURL directive.

WizardImageFile directive defines the location of bitmap, displayed on the left side of first and last page of Setup process. You can remove directive, if you do not need this, or enter correct file name, if your bitmap is in the installation source directory. If not, enter absolute path to the image file (like c:\myXNAGame\Images\Splash.bmp). Please, note that bitmap cannot be larger than 163x314 pixels.

InfoBeforeFile directive is also optional and it defines the location of text file, displayed on the second page of the installation process. If your text file contains license agreement, use LicenseFile directive instead.

DefaultDirName defines default directory where your game will be installed on target computer. {pf} stands for Program Files. DefaultGroupName defines default Windows Start Menu folder name.

OutputBaseFilename defines the file name of output setup file. You can also attach icon to the file with SetupIconFile directive. Just make sure this is valid .ico file.

[Setup]
AppName=myXNAGame
AppVerName=myXNAGame 1.0
AppPublisher=John Smith
AppPublisherURL=http://www.myXNAGame.com
WizardImageFile=Splash.bmp
InfoBeforeFile=ReadMe.txt
DefaultDirName={pf}\myXNAGame
DefaultGroupName=myXNAGame
OutputBaseFilename=myXNAGame_setup
SetupIconFile=myXNAGame.ico

Languages section

This section defines languages supported by setup program. With ShowLanguageDialog directive you control if langague selection dialog will be displayed to the user, otherwise language will be selected from the local settings on target computer.

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

Tasks section

Tasks section defines which tasks will be performed after installation is complete. Two tasks are defined here, first one creates desktop icon, second one quick launch icon.

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}";
GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}";
GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

Files section

This section defines files that will be included in installation package and installed on the target computer during installation process. Edit locations of DirectX and XNA redistributable files. All neccessery files should be located in the map, where XNA is installed on your computer. Edit location of release version of your game, too.

[Files]
Source: C:\Program Files\XNA\v2.0\Redist\DX Redist\*; DestDir: {tmp}
Source: C:\Program Files\XNA\v2.0\Redist\XNA FX Redist\xnafx20_redist.msi; DestDir: {tmp}
Source: "C:\myXNAGame\bin\x86\Release\myXNAGame.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\myXNAGame\bin\x86\Release\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

Icons section

This section defines which shortcuts will be created in the Start menu folder of your game. We will define two icons for Start menu: first one starts the game and second one starts uninstallation process. Desktop and quick launch icons are also defined here.

[Icons]
Name: "{group}\myXNAGame"; Filename: "{app}\myXNAGame.exe"; WorkingDir: "{app}";
Name: "{group}\{cm:UninstallProgram,myXNAGame}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\myXNAGame"; Filename: "{app}\myXNAGame.exe"; WorkingDir:
"{app}"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\myXNAGame";
Filename: "{app}\myXNAGame.exe"; WorkingDir: "{app}"; Tasks: quicklaunchicon

Run section

Run section defines which actions will be executed in the final stage of installation. First we will execute DirectX setup then XNA setup. Third directive will not execute installation, postinstall flag defines that user will be able to launch the game from the "Setup complete" page.

[Run]
Filename: {tmp}\dxsetup.exe; Parameters: /silent
Filename: msiexec.exe; Parameters: "/quiet /i ""{tmp}\xnafx20_redist.msi"""
Filename: "{app}\myXNAGame.exe"; Description: "{cm:LaunchProgram,myXNAGame}";
Flags: nowait postinstall skipifsilent

This script does not include installation of .NET framework, also required to run XNA games, for two reasons:
1. file size of .NET Framework redistributable is more than 20 megabytes - far more than average XNA game
2. .NET Framework is very likely already installed on target system.

When you finish editing the script, select compile option in build menu to start compilation process. This may take a while, current status of compilation is displayed in the lower console. When compilation is complete, you can find your setup file inside Output directory.