Multiple shared projects not possible?

Hello everyone,

I would like to make a cross-platform game and I was able to set up my IDE for that, but I have a problem.
I have the following projects in the solution:

  1. my game engine as a shared project
  2. my game code also as a shared project, which should reference project 1 (this already doesn’t work)
  3. my OpenGL project referencing project 2, but that also doesn’t work as project 2 doesn’t compile.

This is what it looks like

What I’d like to achieve: I’d like to use my engine to develop a game for mobile + PC, therefore the engine’s code must be a shared project, but to be able to test/run the game on PC as well as on mobile, the game’s code must also be a shared project and included in the target platform project file.
The problem is, VisualStudio 2019 doesn’t seem to support using multiple shared projects, as soon as I’d like to use the engine as a shared project in the game code (also shared project) the whole thing breaks. In a nutshell: if I just use the game’s code as an OpenGL project, for example, then including the engine as a shared project works nicely. But if I try to code the game as a shared project, it breaks.

Am I doing something wrong here, or is there any solution to get around this?

Thanks,
Lajos

Instead of a real shared project, this is what I do:

You can edit your csproj to get something similar.

1 Like

I laid out my project structure exactly as your diagram depicts, but I don’t use shared projects. Instead, I used Portable Class Libraries. Like 3 months after I started using this, Microsoft deprecated PCL but you can still make them by copy/pasting an existing one. I can give you one of my old project files if you want, but I think the modern way of doing it just to use .NET Core projects, so maybe give that a try first?

One of these days I’ll go back through all my old projects and update them to .NET Core… oooooooone day :wink:

You can also do it the way Apostolique mentioned. I just prefer not to just because it’s a little more administrative heavy. I like to keep my platform projects super light, containing only an entry point calling my common code, then any platform specific stuff that I need to do.

1 Like

Thanks, what I’ve done is that my engine code is a shared project and the game code is a netstandard 2.1 application which references the engine. I was able to reference the game’s code from a desktop and an android project, it works perfectly for desktop, but for android, I had to copy my whole Content directory to the Android project and I also had to comment out some code to make it work, for example it’s not loading fonts or my json file that contains the map, but at least it’s running now. If I am able to solve these issues, then I guess this is going to be the setup I’ll stick to, it seems convenient.

Yea content is the one I did a bit differently. I just moved it to a common folder and linked each platform entry point project to that. I don’t think it was specifically called a shared project though. I remember using those a long time ago, and I remember that cropping up when I was doing initial investigations, but like you I had trouble getting it to work.

It was just so far back I can’t remember the specifics, just how I ultimately got it working.

I’m not sure of the specifics, but my brain tweaked on you saying you had to comment out some code on certain platforms. I ended up solving that using interfaces and then platform specific implementations.

I’m glossing over a ton of specifics here, but hopefully you get the idea.

In Common Project…

public interface ISomeJob { void DoStuff(); }

class MainEngine()
{
  public SomeDependencyContainer Dependencies { get; } = new SomeDependencyContainer();
}

class SomeClass
{
  private ISomeJob _someJob;
  SomeClass(MainEngine engine)
  {
    _someJob = engine.Dependencies.Get<ISomeJob>();
  }

  void DoTheThing() { _someJob.DoStuff(); }
}

In Windows Project…

class WindowsSomeJob : ISomeJob { /* windows specific implementation */ }

class Program
{
  int main(...)
  {
    MainEngine engine;
    engine.Dependencies.Register<ISomeJob>(new WindowsSomeJob());

    // run
  }
}

In Android Project…

class AndroidSomeJob : ISomeJob { /* android specific implementation */ }

class Program
{
  int main(...)
  {
    MainEngine engine;
    engine.Dependencies.Register<ISomeJob>(new AndroidSomeJob());

    // run
  }
}
1 Like

Thank you!