Setting Up XNA

Setting Up XNA

Important Note: If the script referenced in this tutorial doesn't work for you, please let me know or come find me in the chat room.


In order to get going with XNA, we will need to install a few programs. The good news is, it is all downloadable from the Internet, and it is all completely free! In this tutorial, we will take a look at how to get XNA up and running.

XNA is an add-on for Visual Studio (Pro and Express) that gives you all of the tools you need to make awesome games. This means that the first step will be to install some form of flavor of Visual Studio (if you haven't already) and then we'll install the add-ons afterwards.

Installation will probably take about 20 minutes.

XNA Versions

XNA is currently in its fourth version. The first version, XNA 1.0, was released near the end of 2006. The second version, XNA 2.0, added a great deal in terms of networking and Xbox LIVE support. It was released near the end of 2007. XNA 3.0 was released near the end of 2008, and added better support for audio, because this version also works on the (now obsolete) Zune.

In September 2010, XNA 4.0 was released, which added even more cool features, like support for the Windows Phone 7, microphone recording, and video playback.

If you are starting from scratch, I would recommend that you use XNA 4.0. Through the rest of this tutorial, I'm going to assume that we want to install XNA 4.0.

Installing Visual Studio Express

The first step is for us to install Visual Studio.

Visual Studio is a "family" of applications, meaning there are several variations that are available to you, all of which do essentially the same thing, but with different capabilities. There are three versions that cost money (Professional, Test Professional, Premium, and Ultimate). The cheapest one (Professional) costs hundreds of dollars, while on the expensive end (Ultimate) it costs thousands of dollars. You might have access to this through work or a university (if you're a student) but otherwise, these amounts are probably way too much for you.

The good news is, there is an Express edition of Visual Studio that is completely free! It doesn't have all of the same features as the paid-for versions, but fear not, you'll be able to make all the games you want without trouble. (I use Visual Studio Express for all of my own personal software development projects, and I've never really felt limited by it.)

Like with the paid-for versions, there are multiple Express editions. In the 2010 editions and earlier, these were based on language. There was a Visual C# Express and a Visual Basic Express, and a Visual C++ Express, etc. Since the 2012 versions, they changed their strategy and made them cross-language, but based on functional category—what type of product want to build. So there's now a Visual Studio Express for Web (designed for making web sites), a Visual Studio Express for Windows Phone (designed for Windows Phone development), and so on.

The one I recommend to people getting started with game development is Visual Studio Express for Windows Desktop. (Though there's nothing wrong with having multiple express editions installed.)

Here's the place to download Visual Studio Express 2013 for Windows Desktop:

The download an installation process is pretty typical, so I won't explain it in detail. (Note that after you select Download, you'll be given the option of downloading the full thing as an ISO and wdexpress_full.exe. If you're downloading it in one place and installing it on a computer without Internet access, use the ISO. Otherwise, use the wdexpress_full.exe which is an installer that will grab the files you want during installation.)

Note that with Visual Studio, you'll eventually be expected to sign in and register the software. It's free, but this is kind of an annoying string they've got attached. They're (not surprisingly) trying to keep track of who's using their software. They will send you occasional emails (but not too many, and you can unsubscribe). At least a part of those emails is letting you know as new versions of Visual Studio come out, so you can stay up-to-date.

Installing XNA

XNA 4.0 was built for the 2010 editions of Visual Studio, and there is not yet a version that works in the 2013 editions. But we're not going to let that stop us. (Though it's always a possibility to go back and run Visual Studio 2010 and install XNA Game Studio directly, if you want.)

The steps to get XNA running in Visual Studio 2013 has, in the past, been kind of rough. It's been a manual, error-prone process that virtually everybody (including me, repeatedly) gets wrong.

So to make life easy for everybody, I've created a script that you can run that will do all of the work for you of getting XNA installed in Visual Studio 2013, and get you ready to go.

In this section, I'll outline how to run this script.

1. Download the Script

The first thing to do is to download the script. I've got it in my BitBucket repository:

Save it to a place where you can find it later, such as the Desktop.

2. Open PowerShell with Administrator Rights

This script is a PowerShell script. For those of you unfamiliar with PowerShell, it's like the traditional command prompt on steroids. This thing is really powerful, and even cooler, it's built on .NET, so you can (with some magic) write C# code that you can then later call from PowerShell.

There's a ton that you could know about PowerShell, but for now, you don't need to know a whole lot. (If you're familiar with the traditional command prompt, you'll be pleased to know that with only a couple of exceptions, everything you've learned there transfers directly over to PowerShell.)

If you're running Windows 7 or later, you've already got PowerShell installed. (Earlier versions of Windows can still run it. You can download it from here:

In this step, you need to get PowerShell started with administrator privileges. It's important that you have administrator rights. The script will run various installers, and without admin rights, none of it will work.

The easiest way to do this is to go to the start menu and search for "PowerShell". This will bring up multiple options, but the one you want is the one called simply "Windows PowerShell" (no "ISE" and no "x86"). But instead of just starting it, right-click and choose Run as Administrator to get it started with admin rights.

3. Navigate to the Script

Starting as an administrator, PowerShell starts in the "C:\Windows\System32\" directory, which isn't where you want it.

You need to navigate to the place you saved the script using 'cd' commands. (If you're familiar with the command prompt, this will be very familiar to you.)

Perhaps the fastest way to get there is to enter a command like the following:

cd "C:\Users\[YourUserName]\Desktop\"

(This, of course, assumes you placed the script on the desktop.)

4. Change the Execution Policy

One of the strange things about PowerShell is that it doesn't let you run scripts by default.

What?! A scripting tool that doesn't let you run scripts? Surely you're joking, Mr. Feynman!"

It's true. It sounds strange, but as a part of the goal of creating a better scripting tool comes the goal of building a more secure scripting tool. This is just an artifact of that goal.

It's easy enough to change though.

What you'll do is run the following command:

Set-ExecutionPolicy Unrestricted

(When you're done running the script, you can change it back by calling Set-ExecutionPolicy Restricted again. It is a persistent setting. Also, you can check the current execution policy with Get-ExecutionPolicy if you're curious.)

5. Run the Script

We're now (finally) ready to run the script.

You can run the script with the following:


(If you just start typing the beginning and push the Tab key, PowerShell is great at auto-completion.

Press Enter, and away it goes!

Running XNA

After running the Visual Studio installer and my script to install XNA, you will be able to get started by running Visual Studio itself. (XNA doesn't show up as a separate program. It's an add-on.)

The script is doing quite a bit of work. It will probably take a few minutes. While it's doing that, skip down do the next section to see what exactly the script is doing.

Once the script finishes, you should be ready to go with XNA! (You can open Visual Studio and create a new project. You should be able to find the XNA templates (there are several of them) in the list. If you see them, the installation worked!)

What the Script Does

Feel free to open the script in an editor and see what it does. (Note, I'm no PowerShell pro. I just play one on the Internet. Forgive me if the code is ugly!)

In short, though, the script does the following.

First, it downloads the XNA installer from Microsoft.

It turns out that the XNA installer is just a self-extracting archive that contains about seven other installers. So the next thing the script does is unpack those "internal" installers.

Six of the seven do exactly what you want them to do, out of the box, so the script runs them each in turn.

The other one is the installer that places files in the right place in Visual Studio. Unfortunately, it's looking for Visual Studio 2010, while you've got a newer version (2012 or 2013 both work with the script). So the script tells this installer to just place the files in a temporary location.

These files are built for Visual Studio 2010 and require some changes, so the script makes the changes and places them in the appropriate place for your version of Visual Studio. (In fact, it does it for all versions of Visual Studio you've got installed, regardless of whether it's 2012 or 2013, and regardless of if it's a paid version or Express for Windows Desktop.)

Unfortunately, Visual Studio doesn't automatically check for new add-ons. (Actually, that's a good thing because it would take too long to check all the time, but in this case, it's bad because we need it to check.) To make it check for new addons, the script deletes the extension cache and has Visual Studio rebuild it. Rebuilding the cache takes most of the time that the script runs for. (Several minutes.)

Once it's rebuilt, everything is ready to go, and the script deletes the temporary files that it created.

The Next Step

We now have XNA Game Studio installed on our computer, and we are now ready to start making a game! Take a look at the tutorial for creating a new XNA project from the template to get started.

Troubleshooting.png Having problems with this tutorial? Try the troubleshooting page!