Getting started with MonoGame.Extended

by Dylan Wilson on 16 May 2019

Quick start

If you're starting a new project I recommend using the MonoGame (.NET Core) template. If you don't have dotnet installed please download the latest .NET Core SDK and follow these steps to create a new project.

  1. Install the MonoGame dotnet new template.

    dotnet new -i "MonoGame.Template.CSharp"
    
  2. Create a new MonoGame project.

    mkdir MyGame
    cd MyGame
    dotnet new mgdesktopgl
    
  3. To create a solution file (.sln) file you can either open the project (.csproj) in Visual Studio and hit Save All or you can generate one with the dotnet tools.

    dotnet new sln
    dotnet sln add MyGame.csproj
    
  4. Add a package reference to MonoGame.Extended.

    dotnet add package MonoGame.Extended --version 3.6.0-beta0001
    
  5. Run the game to make sure everything works :)

    dotnet run
    

If the quick start doesn't suit your needs or you'd like to know how to install MonoGame.Extended in other scenarios, please read on.

Creating a new MonoGame project

MonoGame.Extended works with any of the MonoGame platform projects that support .NET Standard 2.0. I recommend starting with the MonoGame Cross Platform Desktop Project that uses OpenGL for rendering because it is compatible with Windows, Mac and Linux.

MonoGame project templates

If you're only targeting Windows, you could also use the MonoGame Windows Project that uses DirectX but in my opinion there's really no advantage to limiting yourself to one platform even if you only ever plan to make Windows only games.

Of course, you can always choose one of the other project templates to target other platforms (e.g. Android or iOS). Just check to see what version supports .NET Standard 2.0.

.NET Framework

If you downloaded MonoGame and installed it using the installer chances are that you're familiar with creating new MonoGame projects using one of the project templates. This is okay, however, to install MonoGame.Extended you'll need to change the target framework to one that is compatible with .NET Standard 2.0. I recommend targeting .NET Framework 4.7.2 or higher.

Change the target framework

.NET Core

My preferred approach is to create new projects with cra0zy's MonoGame (.NET Core) template as described in the quick start. There are several advantages to using the .NET Core template.

  • The project template is light weight and only contains what you need.
  • MonoGame.Framework.DesktopGL.Core is added as a NuGet package rather than needing to be installed on your machine.
  • There's also a MonoGame.Content.Builder NuGet package for building content.
  • .NET Core is more modern than .NET Framework and is getting better all the time.
  • It's compatible with .NET Standard 2.0 by default.

Of course, there are some potential downsides to consider.

  • Running the game in Visual Studio shows an ugly console window in the background. There are some workarounds to this problem. The simplest is to target .NET Core 3.0
  • MonoGame doesn't officially support .NET Core projects yet (they are maintained by cra0zy) and could be a few commits behind.

Hopefully these minor issues will be resolved in time.

Adding MonoGame.Extended with the NuGet Package Manager

If you're developing with Visual Studio you can find the MonoGame.Extended NuGet packages by using the NuGet Package Manager.

  1. Right click the solution and select Manage NuGet Packages for Solution...
  2. Click the Browse tab and search for MonoGame.Extended
  3. Make sure to check the Include prerelease box and set the Package source to nuget.org

Using the NuGet Package Manager

Select the packages you'd like to install and press the Install button.

Hello World!

To test if everything is working add a using statement to the top of your Game1.cs class.

using MonoGame.Extended;

Then draw a filled rectangle with one of the SpriteBatch extension methods.

protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.CornflowerBlue);

    spriteBatch.Begin();
    spriteBatch.FillRectangle(100, 100, 200, 200, Color.Red);
    spriteBatch.End();

    base.Draw(gameTime);
}

Run the game and you should see a red rectangle!

Hello MonoGame.Extended