Cross-Platform Conditional Compilation Symbols

Describes the conditional compilation variables available for maintaining common source code in XNA Game Studio cross-platform projects.

XNA Game Studio projects define symbols for each compatible platform for use with conditional compilation directives such as #if. You can use this to maintain source code that acts differently on Windows, Xbox 360 or Zune when that source is shared between projects.

The conditonal compilation symbols for each compatible platform are:

Windows PlatformXbox 360 PlatformZune Platform


Where source code needs to support different actions when executing on different platforms, it should use the XNA Game Studio conditional compilation symbols with the #if, #else and #elif directives.

For example, a game that needs to execute on Windows, Xbox 360, and Zune, but calls different services (such as for input devices) for each platform might use the directives in a style similar to this:

      #if WINDOWS

      // Execute code that is specific to Windows

      #elif XBOX

      // Execute code that is specific to Xbox 360

      #elif ZUNE

      // Execute code that is specific to Zune


      // Print a compile-time error message
         #error The platform is not specified or is unsupported by this game.


How To: Draw a Sprite shows an example of conditional compilation where the available screen space is calculated differently for Xbox 360 and Windows.


The Conditional compilation symbols are defined in the Build tab of the Project Designer properties for each project. These symbols are properly established when the XNA Game Studio project is first created or converted for another platform through the conversion wizard.

Community Additions