Single MGCB, Multiple Platforms

Been digging around through sites and videos to find an answer and couldn’t find something definitive.

Is there a way / best practice to target the platform you are building for with one MGCB file?

Consider the following:

  • I am on my primary box – Windows 8.1 Visual Studio 2013 ultimate it builds for Windows
  • I am on my mac box – OS X 10.9.5 Xamarin Studio it builds for MacOS

Ideally it would target the right output folders (bin$(Configuration)$(Platform)*) and switch to the proper /platform: MGCB switch.

Can I use preprocessor directives in the MGCB file?

For testing purposes I simply duplicated my Windows MGCB file and added it to GitHub, as we begin to add content I would prefer to do it once.

Thanks so much!

Take a look at towards the bottom there is a section on Preprocessor Macros :slight_smile:

I personally use bin$(Platform) and obj($Platform) in my .mgcb files. Note setting obj is important so the intermediate files between platforms don’t get mixed up.

@James - Note we plan to directly add support for multiple platforms from one MGCB file in the coming months. In the end the Pipeline GUI tool will handle the work of writing all the preprocessor statements needed to do that.

@Tom Thanks so much; great news!

I’ll be incorporating some of the details shared above in my file/process later tonight – and following up on the GamePad issue for OS X in GitHub.

I’m also going to take a look at the documentation sticky to start compiling a list of all the ‘stuff’ I’ve put together – like templates and gotchas. During the ‘daylight hours’ I’ve been the advocate for TeamCity utilization so I’m eager to apply the knowledge elsewhere as well.

Famous engineer last words… “It Just Works”.

I’ve adjusted my MGCB and build steps for OS X and I am now able to include all resources that get compiled from the MGCB.

  • I have build steps to dump them the output files into the Resources\Content folder.
  • I added a custom ItemGroup to bundle them all up for deployment.

<ItemGroup> <BundleResource Include="Resources\Content\**\*.*" /> </ItemGroup>

Hope this helps others out there looking to simplify.

@dellis1972 - Shouldn’t the template projects for Xamarin Studio already deal with that?

I’ve just encountered this myself and it seems like a bit of a bug to me. Want to make sure I am not just getting the process wrong here, as I am trying to document this for others.

Right now in Xamarin Studio on MacOS, it seems you have to manually copy the resulting xnb files to the /Resources/Content folder of your generated app, or import each to your Content folder and set it’s build action as Content, or it won’t be copied into the resulting .app and your game will crash.

I am assuming this is not desired behavior, but I have not found a way around it. On Windows with Visual Studio the mgcb file is seen as an external resource and handled properly, so it is the only thing you need to include in your build and it just works. This link does not appear to work on Mac requiring the work around James mentioned, or requiring you to manually include your generated content.

Am I simply doing things wrong, it’s quite possible, I don’t often work outside of Visual Studio.

I did some hacky things in my OS X game executable CSPROJ.

    <None Include="Info.plist" />
    <None Include="..\ToolboxProtoContent\ToolboxProtoContentOSX.mgcb">
    <BundleResource Include="Resources\Content\**\*.*" />

My MGCB output detail at the top for my globals.

#----------------------------- Global Properties ----------------------------#


I also live mostly in Visual Studio, but I hope this helps. Holler if you have any more questions.

Actually I got it working, but as you said, in a hacky manner. I simply dont want to tell others that this is how you do it on Mac if there is a better way.

Otherwise it seems the best suggestion to users is to have the content pipeline output folder set to the Content folder for MacOSX projects. Which also seems gross. Unless a better way is found I guess I will just advise to add content manually on a Mac.

Thank you however.


I’m working on getting the Content .targets files working on the Mac, exactly as they do in VS. Content compiled via the MGCB (which will be done automatically) will be included Automatically. No need to add/edit the csproj.

It am very close to getting the all working. I’m post a link to the PR once its up.

1 Like