3 min read

Packaging your Source Code for Other XNA Users

Introduction

This tutorial discusses the second method for distributing your game that was listed in the Distributing your Game tutorial. If you haven’t taken a look at that tutorial, it might be worth looking at it now. This tutorial discusses how you can distribute the source code of your game to your friends who have XNA Game Studio, by placing the project in a compressed .zip file.

Packaging your Source Code for Other XNA Users

The first step of packaging your game using this method will be to clean up your game’s solution file structure. The reason for this is that if we send the entire project structure as-is, the file we send will be huge. This has complications with things like email attachment limits and so on. So we’ll start by taking one of two approaches to cleaning up your project directory, removing any compiled code, executables, and compiled art assets (all of which can be rebuilt by the person you’re sending this to.

Option 1: The Clean Command

Packaging your source code is more difficult to do than simply packaging your game, but even this isn’t too difficult. The first step that we will want to do is clean our solution. This will remove any unnecessary files from your project, like build files, and compiled code and art assets. To do this, on the Build menu, click on Clean.

Option 2: Manually Cleaning Your Project

Alternatively, you can do much of the work of cleaning your project manually, if you don’t want to add or use the Clean command. To do this, browse to your game’s directory on your computer. (This should be something like “C:\Users<your user name>\Documents\Visual Studio 2010\Projects<your project name>”.)

In your main game directory, you’ll see your solution file (".sln") and another folder containing the rest of your game. Go into that folder. In here, you’ll see a separate folder for each project in your solution. (At a minimum, there will be one for the bulk of your game and one for your game’s content project.)

Inside each of these folders, you’ll find a bin and a obj folder. You want to delete these two folders for all of the projects you have in your solution. (So at a minimum, you’ll be deleting two bin folders and two obj folders.)

Finishing the Packaging in a .zip File

Once the project has been cleaned, go open Windows Explorer and browse to the directory of your project. Select the directory, and right-click on it, and choose ‘Send To’, and then Compressed (Zipped) Folder’. This will take the entire directory, including your source code and art assets, and put it into a .zip file.

You can then send this .zip file to your friend.

Opening an XNA Game Packaged This Way

When you get a .zip file, you can unzip it by right-clicking on it, and choosing ‘Open With’, and then choosing ‘Compressed (zipped) Folders’. This will allow you to unzip the contents of the .zip file into a directory on your computer.

Open XNA Game Studio and from the File menu, choose Open Project…. Browse to find the directory where the project was unzipped to. Open the file that has the extension .csproj, and the project will be opened. You can now view the source code and art assets in the game, along with compiling the game and running it.

Tradeoffs

This method is somewhat more complicated than packaging only the executable game. However, this allows you to give the source code to a friend, which has its own benefits.