Referencing MonoGame

Missing Microsoft.Xna.Framework Reference

Symptom

Your project references MonoGame objects (in the Microsoft.Xna.Framework namespace), but you have compile errors.

These compile errors may be on using statements such as

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

Solution - Project Not .NET 6

If you are using MonoGame 3.8.1 or newer, then your game project must target .NET 6 or newer. Note that to use .NET 6, you must use Visual Studio 2022 or newer.

You can identify the version of your game by double-clicking the Project in Visual Studio, or by opening the .csproj in a text editor.

For example, the following project is targeting .NET Core 3.1:

Modify this version to .NET 6 by changing the TargetFramework version to net6.0-windows or net6.0 if you plan on targeting other platforms.

For example, after the change the text may appear as shown in the following snippet:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <PublishReadyToRun>false</PublishReadyToRun>
    <TieredCompilation>false</TieredCompilation>
  </PropertyGroup>

Unable to find package MonoGame.Framework.DesktopGL. No packages exist with this id in source...

Symptom

Visual Studio shows errors about NuGet packages not existing in the source. You may see something about Microsoft Visual Studio Offline Packages.

Solution

Check the NuGet Package Sources:

If nuget.org is not listed, click the + button, set the name to nuget.org and set the source to https://api.nuget.org/v3/index.json

Last updated