Search code examples
linuxwindowsmacoscross-platformmonogame

Setup project Cross-Platform with Monogame


I've been trying to figure out on how to setup a Cross-Platform project for MonoGame. Whats the conventional way of doing so ? Is that done through a Shared Project and can I keep all my content in 1 project ?

Also I am not sure if this information is correct do I need a Mac to build my project for Mac how does that work ? If so how what's the best way of setting that up.

Targeted Platforms : WINDOWS, LINUX, MAC


Solution

  • The best way to setup a cross platform MonoGame project IMO would be to use a Shared project. Shared projects can also include .mgcb file so you won't need to duplicate your content either. How to do:

    1. Use "Xamarin Studio/MonoDevelop" and create a "MonoGame Shared Project" with the name of your game
      • If you are going to use using "Visual Studio", close the "Xamarin Studio/MonoDevelop" after this, and open up the created project vith it
      • you are gonna have to include the generated "Content\Content.mgcb" file with build action "None" so it will be visible in Project View area
    2. Add a MonoGame Project for the platform you wish to launch the game from, ie. create a "MonoGame Crossplatform Project" and name it "(gamename).DesktopGL"
    3. Delete "Game1.cs" and "Content Folder" from the Platform project
    4. Add a reference for your Shared project
    5. For your platform project, in options set the Output Assembly Name to be the same as your shared project
      • this step might not seem important, but if you are using a custom importer/processor this will allow you to not have to compile the content separately for each platform.

    There you go, you should be able to run your project now.

    Also I am not sure if this information is correct do I need a Mac to build my project for Mac how does that work ? If so how what's the best way of setting that up.

    The created executable from DesktopGL project is runnable on Mac even when compiled from Windows, the Mac user just has to launch it using Mono. In case you want you can package your game using MonoKickstart so that your Linux and Mac users don't have to have mono installed: https://github.com/MonoGame/MonoKickstart what's more, it also includes other needed native libraries. Description on how to use it are in the link.