Sharing MonoGame Projects: Windows/Linux

TLDR: Is there a way to create one solution with projects for Windows, Linux, and shared/common code?

I tried creating a MonoGame Linux solution using these instructions. Based on my past experience with 2.x, I created two projects:

  • A CoreGame project with my Game class and content-pipeline file (.mcgb)
  • An application project (App) that references the CoreGame project (for Linux)

I can add assets, build, and run on Linux. I then tried opening my solution in Windows with VS2012. It failed, citing that the project types are incompatible with VS; both the App and CoreGame projects.

I wanted to create the CoreGame and windows application projects in VS, but none of them matched what I see in Linux ā€“ thereā€™s no shared project type. Thereā€™s a Windows project (which doesnā€™t run IIRC, something about a missing DLL) and a Linux project, but nothing like that on MonoDevelop in Linux.

Is there a way to create one solution with projects for Windows, Linux, and shared/common code? (libGDX does something similar where 99% of your code is in a shared lib, and you have per-platform projects that just build/wrap platform-specific stuff)

1 Like

Protobuild will do what you want. Iā€™ll post a bit more of a detailed instruction on how to get set up, but basically if you go to http://protobuild.org/ and download Protobuild (from the Get Started link), then place it in a folder where you want your project. Open up a command prompt and run:

Protobuild.exe --start http://protobuild.org/MonoGame/Template.2DPlatformer@develop MyProject

Once this finishes running, you should have a solution for your current desktop platform. To generate for a different platform, use e.g.:

Protobuild.exe --generate Linux

Iā€™ll update this post tonight with more info (feel free to leave questions in the meantime).

@hachque is there a way to do this without Protobuild, with just vanilla MonoDevelop and Visual Studio?

Iā€™ve been looking at Shared Projects as a possible alternative solution to this problem. VS2015 allows Shared Projects to be used for most / all project types.

Iā€™m not sure about MonoDevelop / Xamarin Studio support for Shared Projects though.

@tgjones what solutions exist today? Is there anything with one solution for both? It seems like Visual Studio has better support on this front than MonoDevelop.

@ashes999 Not really; MonoDevelop doesnā€™t support any conditional project logic, which means you canā€™t put conditionals for different platforms in there (no conditions on what files you have or what references you have). Itā€™s the whole reason I ended up building Protobuild, because there was no way to use conditionals in MSBuild and have it work in all IDEs on all platforms.

For what itā€™s worth, my approach is to have one solution per platform, but with all my shared content/code on dropbox and added via linking the files to the various projects. Works a treat and itā€™s very easy to keep platform-specific code (eg: facebook integration, IAP etc) isolated.

Only downside is when I need to rename a file or add a new one as I have to go through all the solutions and update.

1 Like

@Ben_P1 I was afraid it would come to that. Thanks.

Portable Class Libraries (PCLs) were invented for this very purpose, but they come with their own set of problems.

There is an (unofficial) PCL version of the MonoGame NuGet package here: http://www.nuget.org/packages/MonoGame-Portable/. It will hopefully become official with the next release of MonoGame.

Hi all,

Iā€™m also trying to have it so one Solution, many Projects, builds on Mac & Windows (using Visual Studio in both).
Iā€™ve got a ā€œMonoGame Shared Projectā€ with the core game code.

The same Solution (as all in Git source control) all builds fine on Mac, and I thought the same Solution (as ignoring the iOS/Mac projects) were building fine on Windows, butā€¦ just tried it again and Iā€™m getting lots of errors?

Basically, Visual Studio seems to be complaining that it canā€™t find (has no knowledge of) any MonoGame core types - even ā€œGameā€ type is undefined. Yet the same solution/shared project builds fine on VS for Mac.

Also, in Windows - itā€™s seems to keep trying to load the Content (.mcgb) file twice?

Any suggestions? :confused:

Make sure you reference MonoGame in the Windows-specific game project. A shared project does not have any references itself as itā€™s always compiled together with another project.

It might be you have defined <MonoGameContentReference> in both the shared project and the Windows specific project. You can try to set the build action of the Content.mgcb file in your Windows project to ā€˜Noneā€™.

1 Like

Thanks @Jjagg - will give these a go tomorrow when Iā€™m back at my Windows machine! :slight_smile:

UPDATE: That seemed to do the trick - thanks again! :smile: