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:
CoreGame project with my
Game class and content-pipeline file (
- 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
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)
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.
@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.
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?
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’.
Thanks @Jjagg - will give these a go tomorrow when I’m back at my Windows machine!
UPDATE: That seemed to do the trick - thanks again!