Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
    
Just for the record: here's the differences between Reach & HiDef according to Shawn Hargreaves. –  Jonathan Hobbs Jun 4 '12 at 23:28
    
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. –  ashes999 Jun 5 '12 at 1:01

1 Answer 1

up vote 4 down vote accepted

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.

You can see a working example here, where the window title changes to show what XNA profile was set.

share|improve this answer
    
thank you a lot! –  Vodáček Jun 5 '12 at 10:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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