Visual Studio 2010, XNA, and you
Let’s talk tech. Presumably, because you’re reading this blog, you’re a geek like me. That means you like shiny new toys and the latest software that hasn’t even reached RTM yet. That means you probably have Visual Studio 2010 (beta or the recently released RC) and/or the Visual C# 2010 Express Edition and want to use that for your XNA development. However as you’ve probably quickly realized, XNA Game Studio is not supported in VS 2010 or VC# 2010 Express. However, you are able to reference the XNA Framework assemblies in VS2010, so you can reach a midway point.
As I mentioned when I introduced Shader Toy, I’m using VS2010 to build that application. Let me walk you through how you can use VS2010 to build programs leveraging the XNA Framework. Please note that VS2010 is not a supported scenario for XNA at this time. As such, please don’t get upset when a particular feature or function doesn’t work properly. This post is simply for those who want to toy with new tech and don’t need or care about official support (or rather, the lack thereof).
First let’s note the main chunk of what you won’t have:
1) You won’t have the content pipeline. If you want to build content, you’ll have to use VS2008 or an external tool.
2) You won’t have deploy for Xbox 360 or Zune. If you want to build an Xbox or Zune game, use VS2008.
So you’ve decided to make a Windows game that doesn’t need the content pipeline. How do we do this?
1) Create a new C# Console Application in VS2010.

2) Right click your project and choose Add References.
3) Scroll through the list of .NET references to find Microsoft.Xna.Frameworkand Microsoft.Xna.Framework.Game and add those to your project.

4) Decide whether you want to build for .NET 4.0 (the new CLR) or .NET 2.0/3.0/3.5 (the old CLR). To choose, right click your project and choose Properties. Then change the Target Framework drop down.
5) In your project properties, change the Output Type to Windows Application.

6) If you’re building against .NET 4.0, you need to add an Application Configuration file to your project. It’s a template in the Add New Item menu for adding files. Be sure to leave the name “App.config”.
Replace the text in the default file with this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
This lets you use V2 runtime assemblies (like the XNA Framework) in a project compiled against the new CLR.
7) Now just build your game. For instance, you could delete Program.cs and add a Game1.cs with this contents:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace MyWindowsGame
{
class Game1 : Game
{
public Game1()
{
new GraphicsDeviceManager(this);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
base.Draw(gameTime);
}
static void Main(string[] args)
{
using (Game1 game = new Game1())
{
game.Run();
}
}
}
}
Which when run gives you the wonderful default CornflowerBlue:

And there you go. You’re off the ground and running building with XNA Framework and VS2010. Have fun.
Possibly Related Posts
(Automatically Generated)Pong in F# with XNA Game Studio
Editing The Default XNA Game Studio Project Templates
XNA 3.0 and .NET Versions
Shader Toy
XNA Game Studio 3.0 Dated for October 30th


Thanks, it’s very usefull !
Спасибо, это очень полезно !