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. If you are using Visual C# Express 2005 or Visual C# Express 2008, this menu item is not a menu item by default. To add this, follow the directions for Adding 'Clean' to the Build Menu.
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 ("<your project name>.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.
What's Next?
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. If you haven't yet seen how to package your game without giving out your source code, you might want to go back and take a look at the tutorial on Packaging your Game for Other XNA Users. You may also want to take a look at the tutorial on Using ClickOnce to Distribute your Game or also the tutorial on Other Ways to Distribute your Game.
Having problems with this tutorial? Try the troubleshooting page! |