What is a "Monogame Shared Project" and how does it work?

Hi all:

I’ve been away from Monogame for several months, but came back to a pleasant surprise - the 3.6 release! I’ve been messing about, and when I create a new project, I see “Monogame Shared Project” as an option.

I played with it for a second, and I see that there is no “build” option - it’s just a collection of code. My main question is how this new project type works, what it is meant for, and why I might use it over a traditional class library.

The first problem I have is that I have no idea how to reference a shared project from a platform project. Do I just add the solution of the shared project to the game solution? (I’m using VS2017 btw). I tried adding a reference like a traditional DLL but am a bit lost.

Any help would be appreciated, or even just a link to lead me in the right direction.


1 Like

Shared Projects are a special type of project that can contain code, but cannot be compiled by themselves. They need to be referenced by another project so it can be built with that project. So what’s different from a class library is that the shared project is always built together with your platform specific project. That means you can use preprocessor directives in the shared project to have platform specific logic (e.g. #if DIRECTX, #if ANDROID) instead of having to inject it. To reference a shared project, make sure it’s in the same solution as your platform specific projects (if not add it by right-clicking on your solution in the solution explorer and then Add > Existing Project…) then open the ‘Add Reference…’ dialog for your platform specific project and look for the Shared Projects in the side bar. Your project should be listed there.

1 Like

OK, thank you! By the way, is there somewhere where I can get a list of all the preprocessor directives used by Monogame?

You’ll need to define symbols yourself in your platform specific projects (somewhere in project properties in VS). MG libs are compiled libraries so you can’t use the symbols defined by MG in your project, they’re only relevant when you’re working​ on MG itself. The symbols used in MG source can be found here: https://github.com/MonoGame/MonoGame/blob/develop/Build/Projects/MonoGame.Framework.definition#L40


Ah, okay, I get it. Thank you very much for helping me sort this out.

1 Like