次の方法で共有


Introduction to Windows game deployment features in XNA Game Studio 3.0 and 3.1

Note - I originally wrote this post when we released XNA Game Studio 3.0, but the content of this post applies to XNA Game Studio 3.1 as well.  

When the XNA Game Studio 3.0 beta was released a couple of months ago, I wrote a blog post describing the new Windows game deployment features that were added for the beta.  Since then, we have released the final version of XNA Game Studio 3.0.  We made some subtle changes to the Windows deployment features that were introduced in the beta, so instead of updating that older beta blog post, I decided to post a new version of it with updated information that applies to the final release of XNA Game Studio 3.0.

There is also some information about Windows deployment in the XNA Game Studio 3.0 documentation.  This blog post is intended to supplement, not replace, that documentation, so there are some topics I do not cover here because they are already in the documentation.  The best place to get started in the documentation is the Distributing Your Finished Windows Game topic.

Prerequisites for XNA Framework 3.0-based Windows games

Windows games created with XNA Game Studio 3.0 require the following components to be installed in order to run correctly on a system that does not have XNA Game Studio 3.0 installed:

  1. The .NET Framework 2.0 or the .NET Framework 3.5 (depending on what version of the .NET Framework you choose to target when creating your game).  The service pack level for the .NET Framework does not matter, so you could also install the .NET Framework 2.0 SP1, 2.0 SP2 or 3.5 SP1 as a prerequisite for your game if you choose to.
  2. The XNA Framework Redistributable 3.0
  3. Your game binaries and content

Deploying XNA Framework 3.0-based Windows games to other computers

In order to deploy your game to other Windows computers, you need to do one of the following:

  1. Ensure that the target computer has all of the necessary prerequisites listed above by asking the end user to install them, then deliver the game as a .zip file or some other file format.  Typically, you will need to package the contents of your \bin\x86\release\ directory and deliver those files to your users.

    Note:  XNA Game Studio allows you to create a .ccgame file that is a compressed cab file with some specific metadata embedded in it.  However, the user must have XNA Game Studio installed on their system (and therefore, must also have a Visual Studio product installed since that is a prerequisite for XNA Game Studio) in order to unpack a .ccgame file.  That usually makes the .ccgame file format less than ideal for game redistribution scenarios - it is typically more useful for developer sharing.

  2. Create an installer that will install the prerequisites if needed and then install the game payload.  Typically, the installer will be a Windows Installer .msi file and a bootstrapper .exe that will check the user's system state and install any of the prerequisites that are not yet present on the system.

    There are a lot of options available for creating a game installer.  Visual Studio 2008 and Visual C# 2008 Express Edition have built-in support for creating ClickOnce installer packages, and Visual Studio 2008 Professional contains a setup/deployment project type that can be used to create MSI-based installers.  There are also other tools that can be used to create installers - I use WiX when creating my installers for example.

Changes made in XNA Game Studio 3.0 for Windows deployment scenarios

In previous releases of XNA Game Studio, deploying Windows games has been a confusing and error-prone process.  This was partly due to not integrating well with Visual Studio deployment features, and partly due to requiring a relatively long list of prerequisites in order for a game to run correctly on a system that didn't have XNA Game Studio installed.

We have improved the deployment process in XNA Game Studio 3.0 by doing the following:

  1. Including the DirectX 9.0c runtime files required for XNA Framework-based games into the XNA Framework redistributable so they do not need to be installed as a separate step anymore.
  2. Including the Visual C++ 2005 SP1 runtime files required for XNA Framework-based games into the XNA Framework redistributable so they do not need to be installed as a separate step anymore.
  3. Updating the build steps for Windows game projects so they will properly include nested content project output in the ClickOnce publishing output for a Windows game.
  4. Creating a Visual Studio bootstrapper package for the XNA Framework Redistributable 3.0 that can be included as a prerequisite for ClickOnce-based installers and/or Windows Installer-based installers.
  5. Configuring XNA Game Studio 3.0 Windows game projects to have a dependency on the XNA Framework Redistributable 3.0 bootstrapper package so that this prerequisite will be included by default when publishing Windows games using ClickOnce.

What is ClickOnce and why hasn't it worked in the past for games?

ClickOnce is an application deployment technology that can be used to publish applications to Web servers or network file shares for simplified installation scenarios.  ClickOnce features have been available in Visual Studio for a couple of versions, but have not worked well with XNA Game Studio for a couple of reasons:

  1. In XNA Game Studio 2.0, the output of nested content projects was not included in the ClickOnce publishing output when publishing in Visual Studio.  There are some advanced steps that can be used to work around this, but they require in-depth ClickOnce knowledge and also require running publishing tools outside of Visual Studio (such as mage.exe and mageui.exe).
  2. Prerequisites needed to run XNA Framework-based games on computers that do not have XNA Game Studio installed have not been integrated into the Visual Studio publishing process in the past, and the requirements for manually creating installers have been poorly (or worse - inaccurately) documented.

As mentioned above, the issues that used to make ClickOnce deployment a complicated process for XNA Framework-based Windows games has been greatly improved in XNA Game Studio 3.0.

How to publish an XNA Game Studio 3.0 Windows game using ClickOnce

There are a couple of ways to access publishing functionality in Visual C# 2008 Express Edition or Visual Studio 2008.  The following steps will allow you to publish using the default settings for prerequisite packages:

  1. Open Visual C# 2008 Express or Visual Studio 2008.
  2. Create a new XNA Game Studio 3.0 Windows game project.
  3. Click on the Build menu and choose Publish <game> (or right-click on your Windows game project in the Visual Studio Solution Explorer and choose Publish... ) - this will launch the Visual Studio Publish Wizard.
  4. Specify the publishing output location.
  5. Choose the installation mechanism to offer to your users - install from the Web, install from a UNC path or file share, or install from a CD/DVD.
  6. Choose whether or not you want to enable automatic updates for your game.
  7. Click Finish to publish (which will trigger a build automatically if your build output is out of date).

ClickOnce publishing output

The above steps will produce a publishing output folder that contains the following:

  • setup.exe - this is the setup executable for your game, and it contains logic to install prerequisites and then trigger ClickOnce to deploy your game payload
  • <game>.application - this is the ClickOnce deployment manifest for your game
  • Application Files folder that contains your game payload

The above steps will automatically configure your game to include the .NET Framework 3.5 and the XNA Framework Redistributable 3.0 as prerequisites.  It will use the default deployment settings for each of these prerequisites.  This means that setup.exe will detect whether or not the user's system needs the .NET Framework 3.5 and/or the XNA Framework Redistributable 3.0, and it will download and install one or both of them if they are missing.

How to configure non-default ClickOnce publishing options

In order to change the default publishing behavior for XNA Game Studio 3.0 Windows game, you can use the following steps:

  1. Right-click on your Windows game project in the Visual Studio Solution Explorer and choose Properties.

  2. In the property pages, select the Publish tab.

  3. Use the Application Files... button to exclude files in your game project from your publishing output.

  4. Use the Prerequisites... button to add/remove prerequisite packages or to change how they are packaged (download from the manufacturer's web site, download from the same location as the application, package in a directory along with the game).

    The Download prerequisites from the same location as my application option in the Prerequisites dialog will cause your build output to include not only your game binaries and content, but also the installer packages for your prerequisites.  This is useful when creating offline installers that do not require Internet access in order to install correctly.

  5. Use the Updates... button to enable automatic update checking and configure the update details.

  6. Use the Options... button to configure other advanced ClickOnce options.

  7. Use the Publish Wizard... button to invoke the publishing wizard (the same one that appears if you click on the Build menu and choose Publish <game> in the previous set of steps.

  8. Use the Publish Now button to publish using the default publishing settings without stepping through the wizard.

Notes about installing Windows games using ClickOnce

After publishing your game, you can install it on another system by running setup.exe or by running <game>.application (if the target system already has the .NET Framework 2.0 or higher, it will know how to handle the .application file extension).  Any missing prerequisites will be installed, and then your game will be deployed.  Here are a few key notes about this deployment process:

  • ClickOnce applications are deployed as per-user application to a randomly-generated folder under the currently logged in user's %LOCALAPPDATA% folder.  This folder is chosen automatically by ClickOnce, and you do not have any control over this location in the publishing process.
  • ClickOnce will create a Start menu shortcut for your game.
  • ClickOnce will create an Add/Remove Programs entry so that the user can uninstall the game later if they choose to.
  • If you choose to include automatic updates for your game, ClickOnce will check for new versions of your game each time the user launches it, and it will deploy new versions if they are available.

Using a setup/deployment project to create a game installer

Visual Studio Professional Edition and higher offers the ability to create MSI-based installers in addition to ClickOnce packages.  Both of these deployment solutions use the same bootstrapper packages for installing prerequisites.  This means you can also use a setup/deployment project in Visual Studio 2008 Professional Edition and higher to create an MSI to install your game, and then include the .NET Framework and the XNA Framework Redistributable 3.0 as prerequisites.

It is important to note that XNA Game Studio 3.0 does not support automatically adding game or content project output to the setup project (which is normally done by right-clicking the setup project, choosing Add | Project output... and selecting the primary output of the desired project in the Add Project Output Group dialog).  As a result, you will have to manually add the binary files and content files that you want to install as a part of your game to your setup project one-by-one if you choose this option.

Here are steps that you can use to accomplish this:

  1. Open Visual Studio 2008 Professional or higher (setup/deployment projects are not available in the Standard or Express Editions).
  2. Create a new XNA Game Studio 3.0 Windows game project.
  3. Right-click on the solution in the Visual Studio Solution Explorer and choose Add | New Project...
  4. Go to Other Project Types | Setup and Deployment and add a Setup Project.
  5. Use the File System designer to populate the project with the payload of your game (content plus game binaries).  To do this, right-click on your setup project and choose View | File System.  Then create folders and add files in the desired locations.
  6. Right-click on your setup project in the Solution Explorer and choose Properties.
  7. Change the Configuration drop down if you want the changes to affect both debug and release builds.
  8. Click on the Prerequisites... button to bring up the Prerequisites selection dialog.
  9. Scroll to the bottom and check the item named Microsoft XNA Framework Redistributable 3.0, then click OK.
  10. Build your solution.

After a build, your setup project's output directory will contain the following by default:

  • setup.exe - this is the setup executable for your game, and it contains logic to install prerequisites and then trigger the installation of your MSI
  • <game>.msi - this is the Windows Installer MSI file that contains your game payload

Limitations in Windows game redistribution scenarios in XNA Game Studio 3.0

The above information describes how to create an installer for an XNA Framework-based Windows game.  There are a couple of key scenarios that are not currently possible when deploying a Windows game to a system in this way because the necessary functionality is only installed by XNA Game Studio, not by the XNA Framework Redistributable:

  • The Microsoft Games for Windows - LIVE Redistributable package is installed during XNA Game Studio setup, but it is not available for redistribution as a part of a game installer.  A Windows game that attempts to use networking functionality provided by this package on a system without XNA Game Studio installed will encounter a GamerServicesNotAvailableException.

  • The Content Pipeline Build Runtime is installed during XNA Game Studio setup, but it is not included in the XNA Framework Redistributable.  Building content at run time (which could be used for things like level editors and game modding engines) is only supported when XNA Game Studio has been installed on the Windows-based development computer.

    Note: If you use XNA Game Studio content pipeline extension projects in your games, make sure that you only reference them from your content projects and not from your game project.  If you reference a content pipeline extension project from a game project, that will cause the content pipeline to be required at runtime for your game (and not just at build time), and your game will not work if you deploy it using ClickOnce or a setup/deployment project because the XNA Framework Redistributable 3.0 does not include content pipeline binaries.

Behind the scenes details if you are interested

If you are interested in more details, you can see the data files for the XNA Framework Redistributable 3.0 bootstrapper package by looking at the folder %ProgramFiles%\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\XnaFxRedist30 on a system with XNA Game Studio 3.0 installed.  We created this bootstrapper package by using the steps in this MSDN document about creating custom bootstrapper packages.

Advanced scenarios

I have written a few supplemental blog posts about the following more advanced Windows game deployment topics:

If you have any suggestions for additional topics, please let me know.

Summary

Windows game packaging and deployment have been consistent pain points since the first version of XNA Game Studio Express.  Hopefully the features that we've added in XNA Game Studio 3.0 will end up being useful in making this process simpler and less error prone.  If you are creating Windows games using XNA Game Studio 3.0, I encourage you to try out the deployment features and let us know if you run into any troubles using these features and/or have any suggestions for further improvements by posting on the forums and/or reporting bugs on the Connect site.

<update date="11/16/2008"> Added information about the XNA Game Studio 3.0 documentation topic about Windows game deployment. </update>

<update date="11/18/2008"> Added a link to the online documentation for XNA Game Studio 3.0 now that it has been published. </update>

<update date="11/21/2008"> Added links to additional blog posts about advanced deployment scenarios that I have written since this post was initially published. </update>

<update date="4/14/2009"> Added a link to a new post I wrote about integrating with Windows Game Explorer . </update>

<update date="8/24/2009"> Added a note about XNA Game Studio 3.1. </update>

Comments

  • Anonymous
    November 03, 2008
    PingBack from http://blogs.msdn.com/astebner/archive/2008/09/18/8957968.aspx

  • Anonymous
    November 03, 2008
    Thanks for pointing me to the correct writeup!  Clear as a bell, Best, Byron

  • Anonymous
    November 03, 2008
    If you are using ClickOnce to deploy a Windows game created with XNA Game Studio 3.0, you might run into

  • Anonymous
    November 05, 2008
    Any thoughts on using obfuscation with ClickOnce when distributing and XNA GS3.0 application for windows? Are we still condemned to Mage and MageUI? Would you recommend just not using ClickOnce given the added hurdles of having to manually build the deployment packages? And if so what is the best alternative solution? Many thanks.

  • Anonymous
    November 05, 2008
    The comment has been removed

  • Anonymous
    November 05, 2008
    PingBack from http://www.igrophile.com/introduction-to-windows-game-deployment-features-in-xna-game/

  • Anonymous
    November 15, 2008
    Great article! Cleared up a lot of things for me. When I installed a ClickOnce publish named spacewar on another machine the game did not work, until I moved the settings.xml from the spacewar...exe directory to the spacewar..tion directory. The project is the spacewar 2.0 base project upgraded to 3.0. Anyone have an idea what might be going on? Thanks, Stephan

  • Anonymous
    November 16, 2008
    Hi Holon777 - ClickOnce treats .xml files as data files by default and installs them to a special data file folder when deploying an application.  There is a section in one of the XNA Game Studio 3.0 documentation topics that explains how to handle this. You can find the topic at XNA Game Studio 3.0 | Using XNA Game Studio | Sharing and Distributing Your Game | Distributing Your Finished Windows Game in your XNA Game Studio 3.0 documentation table of contents.  The section you'll want to look at in that topic is titled Special Consideration for Game Data Files. Also, in the updated 3.0 version of the Spacewar starter kit that is available at http://creators.xna.com/en-US/starterkit/spacewar, we have fixed this deployment issue related to settings.xml.

  • Anonymous
    November 17, 2008
    I previously wrote an introductory post describing Windows game deployment features that are a part of

  • Anonymous
    November 18, 2008
    Thanks Aaron, I followed the instructions and my installs are working!

  • Anonymous
    November 19, 2008
    Aaron Stebner's WebLog : Introduction to Windows game deployment features in XNA Game Studio 3.0

  • Anonymous
    November 21, 2008
    A few days ago, I wrote a blog post describing how to create an MSI-based installer for a Windows game

  • Anonymous
    November 25, 2008
    Since we released XNA Game Studio 3.0 , I've heard of a few problems from customers via my blog and the

  • Anonymous
    April 13, 2009
    I’ve previously written a few posts about how to get started with Windows game deployment for games created

  • Anonymous
    May 31, 2009
    Why doesn't my content get included with ClickOnce?  The installer can't find my only .png file.

  • Anonymous
    June 02, 2009
    Hi Rokit5 - Is your .png file included in your content project, or did you add it to your code project?  If it is in the content project, it should be picked up automatically by the ClickOnce publishing command.  If it is in the code project, you need to make sure to set the attributes appropriately to cause them to be published. There is a note in the "Special Considerations for Game Data Files" section of the documentation topic at http://msdn.microsoft.com/en-us/library/bb464156.aspx that explains how to set the attributes for files like this if they aren't in the content project. Hopefully this will help.

  • Anonymous
    June 03, 2009
    For anyone reading these comments in the future, there is a more in-depth discussion of Rokit5's issue in the Creators Club forums at http://forums.xna.com/forums/p/32159/185794.aspx, including a workaround that can be used to allow ClickOnce publishing to work for the project in question.  The underlying issue was some missing metadata in the game's .csproj file that caused it to skip publishing files in the nested .contentproj.  The metadata should be populated by default when creating new projects with the XNA Game Studio project templates, but the game being used in this case was from a Creators Club sample that was not created with an XNA Game Studio project template and was missing some required metadata.