# Managing cross-platform targets/compatibility with Monogame

I recently started using Monogame for the first time because of it's cross platform compatibilities and heavily active development. The first thing I did is installing the whole framework using their provided installer, but as soon as I wanted to make my first Monogame project, I noticed the following:

Although being cross-platform, there is no real 'Monogame' library. The framework ships with multiple assemblies for several platforms, each with their own dependencies. This is reflected both in the Visual Studio project templates as well as for the nugets they provide.

Now I'm wondering: Is there a straightforward way to just develop with the Monogame framework 'itself' in the first place, and then deciding on platform etc. later by using build targets and conditional compilation? Or do I just have to reference every assembly and it will work out of the box? What's your approach when developing with Monogame for different platforms? Making a .NET project for every target platform?

Their documentation unfortunately doesn't describe the different platform assemblies. They are just there, ready to be used with the infomation that Monogame IS cross-platform compatible.

Monogame game is cross-platform compatible, but not in the sense that you just magically click and it will work. In most cases, you are going to need to tweak individual builds, in order to get them to function properly in each environment.

If you consider supporting iOS or Android, you are going to have to look into the xamarin dependencies as well, which are not even part of the Monogame framework at all.

Fortunately, most of the code will just work. It is a matter of getting the builds to compile and work as intended on each environment. There will almost always be at least some minor issues, you will need to compile and try it for each supported environment.

• Ah, that's what I was afraid of. Well then it's something future me has to worry about, for now I just start developing. Thanks! Jun 8 '15 at 21:54
• Yeah, you can worry about each individual port later on. Get coding :) Jun 8 '15 at 21:56

In Monogame, the source code of your game is the only thing that is identical for every platform. Of course you would have to change how you handle inputs for every platform (for example windows doesn't have touch) and how you calculate the screen size (mobile doesn't have multi-monitor setups). If you chose to use the #IF __ANDROID__ and #IF WINDOWS keywords in your code and inside your visual studio project, then you will basically have a common source code folder and you will be able to copy paste it between projects to bring them up to date.

Typically, the best way of developing games is to first develop it for windows Desktop and then when you are finished developing your game, spend a couple of minutes making an Android (or any other) project and setting it up. This is because Desktop projects compile so much faster.

There is no reason to worry about multi-platform until the moment you are ready to deploy your game. Note that you will need a 25\$ license from Xamarin to compile your game for Android/iOS. That license lasts for 1 month, but you actually only need it just for the few seconds that it takes to compile (if you are not planning on adding content to your game and having to re-compile at least). The free trial version of Xamarin only produces .apk (and the equivalent for iOS) which last for 24-hours.

As for the dependencies, here is how my project looks like when I build from Monogame's source code. Windows DirectX (on the left) and Android (on the right). Its pretty straight forward. Monogame.Framework.Windows.dll and SharpDX.dll(s) for windows. And Monogame.Framework.Android.dll and OpenTK.dll for Android. You would be able to compile these 2 projects without having anything Monogame related installed. Because I reference the dlls such as SharpDX.dll locally (I have placed them in a SharpDX/ folder inside my Monogame.Framework.Windows library-project).

• Hey, thanks for your comprehensive answer. Too bad I can't upvote on gamedev yet. :( Am I right to assume that the Android/Windows projects are seperate .NET projects linking to the same set of files? Jun 8 '15 at 22:21
• @artganify The way I have set it up is that they are 2 completely different projects (solutions is the correct term). The way I work is I develop it on Windows and when I feel like checking "if it works" on Android all I do is copy that "Source" folder you can see in my screenshot from one project to another. This is achieved because of the #IF __ANDROID__ and #IF WINDOWS keywords I have set up as I said in my answer. These keywords are used very rarely. (only for screen-size calculation, handling inputs and the MainActivity class for the Android version) Jun 8 '15 at 22:27