How to setup multiplatform game without Visual Studio?

Hello!
I’m trying to setup a Monogame project that compiles to multiple platforms using Visual Studio Code. I looked it up online and all the tutorials I found talk about using Visual Studio to do it. I know I should use a “MonoGame Shared Library Project”, but I have no Idea how to connect it to the other projects and compile the game for a specific platform (like Android).
Is there some resource that explains it step-by-step?
Thank you in advance!

You can use MonoGame Kickstarter if you like
GitHub - Kwyrky/MonoGame.Kickstarter: A bash script that sets up a MonoGame solution ready for cross-platform development

What works for me is editing the .csproj files manually. For example, to add a reference to a shared project to an Android you would add the following codd:

    <ProjectReference Include="..\Psilibrary\Psilibrary.csproj">
      <Project>{5fa0a250-9c95-4ee0-ac88-f499f66af97b}</Project>
      <Name>Psilibrary</Name>
    </ProjectReference>
  </ItemGroup>

Replacing the project name, path and GUID with your values.

So I tried your method and I couldn’t reference the shared project in Program.cs, it didn’t see it at all. So I tried "dotnet add reference " command and it threw “The imported project “C:\Program Files\dotnet\sdk\3.1.402\Microsoft\VisualStudio\v16.0\CodeSharing\Microsoft.CodeSharing.Common.Default.props” was not found.”
I tried updating dotnet and googling it, but found nothing useful, any idea why it might not work?

Shared projects and referencing projects are 2 different things and they need to be referenced differently. The former is a collection of source files that is bundled with your project and compiled when you compile your game. The latter is a pre-compiled assembly.

You can reference a shared project like this

<Import Project="..\MySharedProject\MySharedProject.projitems" Label="Shared" />
1 Like

Thank you! This worked.

I used shared projects in the past myself but I switched to dotnet standard library. It is the recommended way now I think?

If MonoGame Kickstarter seems to be overcomplicated it is just because me writing to verbose maybe.

To try it you in Windows you just need to have git installed. Git automatically comes with git bash which is a command line or terminal.

You just have to clone the MonoGame Kickstarter repository from GitHub (the link above) using the command “git clone https://github.com/Kwyrky/MonoGame.Kickstarter.git”. Then run the script and give it a name for your new project(s) / solution.

The solution can be opened and build in visual studio.

@nanoblit If it would help I can maybe record a short video of the process?

Shared projects is still useful in the cases where you want to have a “core” codebase that handles code between different platforms (windows, linux, android, playstation 4, playstation 5, etc.), since it allows you to leverage preprocessor directives.

Prefer to use regular projects that compiles to reusable assemblies in most cases, but in this case shared project is appropriate.

1 Like