Hey! I'm David Amador,
and I'm a programmer. I do mostly game development. Oh I have a twitter

My latest Game

This is the latest game I developed. Buy it if you want to support me and my work. More info

Latest tweets

    Making a XNA Game Installer

    9 Jun
    2010

    I am going to start with a little rant about Visual Studio default Installer, you know, the one you can make for yout XNA games inside VS. Ugly and not very handy, sure it installs every dependency but doesn’t leave many options like….hum…I don’t know choosing the location where you want to install?

    Moving along…I discovered this little cool installer called InnoSetup, and best of all it’s free.

    InnoSetup has different ways of you building a proper installer but I am going to cover the script way, much more control.

    I found a little startup script from Caliban Darlock for XNA 2 I think and I modified it for XNA 3.1

    Start by downloading vcredist_x86.exe, DotNetFX35Setup.exe and xnafx31_redist.msi and place them in a folder, I placed mine on D:\Game Development Tools\

    Then onto the script

    ; Script generated by the Inno Setup Script Wizard.
    ; (Then extensively modified by Caliban Darklock.)
    ; (And yet again modified by David Amador) Should work property with XNA 3.1
    ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
     
    ; Enter the name of your game here
    #define MyAppName "Vizati"
     
    ; Enter the name of your game and a version number here
    #define MyAppVerName "Vizati"
     
    ; Enter the name of your company, or just your name
    #define MyCompany "Different Pixel"
     
    ; Enter the URL of your website
    #define MyAppURL "http://vizati.differentpixel.com/"
     
    ; Enter the path to your game project - check Visual Studio properties for the path
    #define MyAppLocation "D:\Projects\Vizati\Vizati"
     
    ; Enter the name of your game executable
    #define MyAppExeName "Vizati.exe"
     
    ; Enter the location where XNA Game Studio is installed
    #define MyGameStudioLocation "C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v3.1"
     
    ; Enter the name for the correct version of the XNA Framework MSI
    #define XNARedist "xnafx31_redist.msi"
     
    ; Enter the location where you have placed the VC and .NET redistributables
    #define MyRedistLocation "D:\Game Development Tools"
     
    ; search microsoft.com for "visual c++ sp1 redistributable" to get the VC redist
    ; enter the name of the executable file here
    #define VCRedist "vcredist_x86.exe"
     
    ; Download latest .NET from http://www.microsoft.com/net/ (download button on menu)
    ; enter the name of the executable file here
    #define DotNetSetup "DotNetFX35Setup.exe"
     
    ; Once you've filled in all the variables above and downloaded your redist packages,
    ; everything under this point should JUST WORK for most XNA projects.
     
    [Setup]
    AppName={#MyAppName}
    AppVerName={#MyAppVerName}
    AppPublisher={#MyCompany}
    AppPublisherURL={#MyAppURL}
    AppSupportURL={#MyAppURL}
    AppUpdatesURL={#MyAppURL}
    DefaultDirName={pf}\{#MyAppName}
    DefaultGroupName={#MyAppName}
    OutputBaseFilename={#MyAppName}Setup
    Compression=lzma
    SolidCompression=yes
    SetupIconFile = "D:\Projects\Vizati\Vizati\vizati.ico"
    UninstallIconFile = "D:\Projects\Vizati\Vizati\vizati.ico"
     
    [Languages]
    Name: english; MessagesFile: compiler:Default.isl
     
    [Tasks]
    Name: desktopicon; Description: {cm:CreateDesktopIcon}; GroupDescription: {cm:AdditionalIcons}; Flags: unchecked
     
    [Files]
    ; DirectX and XNA Framework redistributables
    Source: {#MyGameStudioLocation}\Redist\DX Redist\*; DestDir: {tmp}
    Source: {#MyGameStudioLocation}\Redist\XNA FX Redist\{#XNARedist}; DestDir: {tmp}
     
    ; .NET and VC redistributables - VerifyDotNet35 MUST run BEFORE VerifyDotNet35sp1!
    Source: {#MyRedistLocation}\{#DotNetSetup}; DestDir: {tmp}; AfterInstall: VerifyDotNet35
    Source: {#MyRedistLocation}\{#VCRedist}; DestDir: {tmp}; AfterInstall: VerifyDotNet35sp1
     
    ; The game itself
    Source: {#MyAppLocation}\bin\x86\Release\{#MyAppExeName}; DestDir: {app}; Flags: ignoreversion
    Source: {#MyAppLocation}\bin\x86\Release\*; DestDir: {app}; Flags: ignoreversion recursesubdirs createallsubdirs
     
    [Icons]
    Name: {group}\{#MyAppName}; Filename: {app}\{#MyAppExeName}
    Name: {group}\{cm:UninstallProgram,{#MyAppName}}; Filename: {uninstallexe}
    Name: {commondesktop}\{#MyAppName}; Filename: {app}\{#MyAppExeName}; Tasks: desktopicon
     
    [Run]
    Filename: {tmp}\{#DotNetSetup}; Flags: skipifdoesntexist; Parameters: "/q /noreboot"
    Filename: {tmp}\{#VCRedist}; Flags: skipifdoesntexist; Parameters: "/q"
    Filename: {tmp}\dxsetup.exe; Parameters: /silent
    Filename: msiexec.exe; Parameters: "/quiet /i ""{tmp}\{#XNARedist}"""
    Filename: {app}\{#MyAppExeName}; Description: {cm:LaunchProgram,{#MyAppName}}; Flags: nowait postinstall skipifsilent
     
    ; The code section doesn't like comments for some reason.
    ; VerifyDotNet35 removes the .NET setup if you already have .NET 3.5 installed.
    ; VerifyDotNet35sp1 removes the VC redist if you already have .NET 3.5 SP1, -or-
    ; if you don't have .NET 3.0 at all (it will be installed along with .NET 3.5).
    ; Using the skipifdoesntexist flag allows the setup to ignore the missing files.
    [Code]
    var
      hasDotNet3 :Boolean;
      hasDotNet3sp :Boolean;
      whichDotNet3sp :Cardinal;
     
    procedure VerifyDotNet35();
    begin
      hasDotNet3 := RegKeyExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5');
    	if hasDotNet3 then
          DeleteFile(ExpandConstant('{tmp}\{#DotNetSetup}'));
    end;
     
    procedure VerifyDotNet35sp1();
    begin
      hasDotNet3sp := RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5', 'SP', whichDotNet3sp);
      if (hasDotNet3sp and (whichDotNet3sp > 0)) or not hasDotNet3 then
          DeleteFile(ExpandConstant('{tmp}\{#VCRedist}'));
    end;

    So you can basically copy paste this and save it as a .iss file. Should open on double click with Inno Setup Compiler once you install it.

    It’s pretty straight forward and you can modify it with your paths and specific need.

    Things to care about:
    #define MyAppLocation – This is where your Game Project is, typically one folder below the solution
    #define MyGameStudioLocation Folder to XNA Game Studio 3.1 Installation
    #define MyRedistLocation Folder where vcredist_x86.exe and xnafx31_redist.msi and DotNetFX35Setup.exe should be

    The installer will also fetch every file inside you Release Folder. So you might wanna delete those .pdb files before doing it.

    Hit Compile and there you go.

    If everything goes alright the installer should test the registry for XNA and .NET 3.5 and install it if needed. I used Virtual PC with a clean Windows XP installation to test it and it worked. XNA got installed =)

    Related Posts:

    9 Responses to Making a XNA Game Installer

    Avatar

    Da Voodoochief

    June 9th, 2010 at 22:43

    Hi David,

    I migth get to try this soon, but it will be a very handy reference if i do need it.

    Nice job.

    Da Voodoochief

    Avatar

    Nick

    June 9th, 2010 at 23:23

    To be fair, ClickOnce as a whole doesn’t allow customizing the install path because it is intended to be a per-user, non-admin installation mechanism. It installs the game into the current user’s AppData so it doesn’t need admin privileges and is supposed to be fairly light weight.

    So yes, depending on your desires, you would need to branch out to use other installer technology as you’ve found. :)

    Avatar

    David Amador

    June 10th, 2010 at 8:57

    Hi Nick.
    Yes I understand that, my only bad feeling towards ClickOnce is that it feels rudimentary (even if powerful) compared to the great tool that VS really is. It should have more flexibility. I’m pretty sure tons of users would appreciate it =D

    Avatar

    Robin WILS

    June 22nd, 2010 at 23:41

    Perfect, works great for my game thank you. I had a hard time finding a good tutorial to do this…
    I noted a few things though, I had 3 errors:
    -SetupIconFile = “D:\Projects\Vizati\Vizati\vizati.ico”
    -UninstallIconFile = “D:\Projects\Vizati\Vizati\vizati.ico”
    those two paths need to be changed and
    -Syntax error:
    if (hasDotNet3sp and (whichDotNet3sp > 0)) or not hasDotNet3 then

    I changed the > by > and it worked.
    Thank you

    Avatar

    Robin WILS

    June 22nd, 2010 at 23:43

    I changed “& gt ;” by >

    Avatar

    David Amador

    June 23rd, 2010 at 0:00

    Ahh, thanks for pointing that out. Actually it’s wordpress fault for switching that character

    Avatar

    Robin WILS

    June 23rd, 2010 at 20:08

    Yeah, I saw that :)

    Avatar

    Making an XNA4 Game Installer

    June 27th, 2010 at 5:50

    [...] David Amador put together an excellent piece on creating an install builder for XNA3.1 games using the well known InnoSetup tool. [...]

    Avatar

    putting together an xna4 installer using innosetup – MyGameTeacher

    August 22nd, 2010 at 7:10

    [...] David Amador put together an excellent piece on creating an install builder for XNA3.1 games using the well known InnoSetup tool. [...]

    Comment Form

    top

    Bad Behavior has blocked 45 access attempts in the last 7 days.