Creating a Windows Game Library in VS2015 with Monogame

Let me begin by stating I a fairly new to Monogame coming from XNA as well as game development. I am using Visual Studio 2015 and have installed the XNA 4.0 Refresh. I have a few XNA books with projects that I want to re-create using Monogame. So far things have been working fine. However I am working on a game project that has me baffled on how to complete it.

The project includes building a tile map engine. In the book the author mentions creating a class library for the tile map engine and using Windows Game Library. I remember seeing this when building XNA games using Visual Studio 2010. However it is missing in Visual Studio 2015. The XNA template included references. I tried re-creating the library using the generic Class Library (C#) and the Portable Class Library(C#). However neither worked for me in the project. I get error messages saying that I have un-referenced assemblies. When I add the references in VS, I get additional errors saying that Texture2D, Rectangles, etc. are referenced in both XNA.framework and in Monogame.framework. If I remove the Monogame.framework reference then I get errors regarding SpriteBatch.

What do I need to do so I can build the class library and have it referenced in the actual game project without XNA and Monogame conflicts?

Do you have the right using directives? E.g. for my project I have:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

And nothing related to MonoGame.

  1. Create your monogame project as before by selecting “monogame windows project”

  2. Add a standard class library project

  3. Add a reference in your class library to the monogame DLL
    – Might be in path: C:\Program Files (x86)\MonoGame\v3.0\Assemblies\Windows

  4. Add the correct using into each of the class files “class1.cs” etc.

  5. Add reference in your main project to the class library project

After following your suggestions I got things to work as expected. Thank you all for expanding my knowledge of using Monogame with VS2015.

Excellent, glad to help.