I am writing game in XNA 4 and this version have two profiles hi-def and reach. My problem is that I need to have my game code for each of these profiles and is very uncomfortable to have two projects and do all changes in both of them. My idea was to use preprocessor directive (i am not sure about name of this, http://msdn.microsoft.com/en-us/library/ed8yd1ha%28v=vs.71%29.aspx) and use IF statement at places with problems with profile. There is only problem that program needs to be compiled two times (for each profile) and manually changed directive and project settings to another profile. And my questions are: Is that good way? Is there better and cleaner way how to do this?

  • \$\begingroup\$ Just for the record: here's the differences between Reach & HiDef according to Shawn Hargreaves. \$\endgroup\$ – doppelgreener Jun 4 '12 at 23:28
  • \$\begingroup\$ Just isolate your view code and use some sort of design pattern like strategy or factory to create objects depending on if it's reach vs. hidef. The rest of your code should be the same. \$\endgroup\$ – ashes999 Jun 5 '12 at 1:01

I got this working, but you need to use some MSBuild magic to do it. I strongly recommend you backup your project, as you might easily break something if you do this wrong.

First things first, you need to open up the configuration manager(ALT + B + O).

Then you need to create four build configurations for your game project. I chose to name mine DebugReach, ReleaseReach, DebugHiDef and ReleaseHiDef.

After doing this, you save your project, right-click the project in the solution explorer and then hit Unload Project. Now, you right-click the project again, and hit Edit <projectname>.csproj. This is the raw MSBuild configuration of your project.

In the first PropertyGroup node, you need to find the child node XnaProfile ann then delete the line. Next you need to find the PropertyGroup nodes that look like this:

  • <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugReach|x86' ">
  • <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseReach|x86' ">
  • <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugHiDef|x86'">
  • <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseHiDef|x86'">

Into DebugReach and ReleaseReach you add the following node:

  • <XnaProfile>Reach</XnaProfile>

Into DebugHiDef and ReleaseHiDef you add the following node:

  • <XnaProfile>HiDef</XnaProfile>

After that, you save the file, close it, then right-click the project and click reload. Now depending on the build configuration you use, you'll either use Debug or HiDef. Please note that opening up Properties does not reflect the difference, but you can test it when you build.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.