MonoGame/KNI/FNA
Introduction
This page assumes you have an existing MonoGame project. This can be an empty project or an existing game.
MonoGame Gum works on a variety of platforms including DesktopGL, DirectX, and mobile. It's fully functional with all flavors of XNA-like libraries including MonoGame, Kni (including on web), and FNA. It can be used alongside other libraries such as MonoGameExtended and Nez. If your particular platform is not supported please contact us on Discord and we will do our best to add support.
Starting From a New Project
If you plan to use a Gum project, the easiest start is a new game that Gum creates for you. In the Gum tool, select File > New Project, check Create C# project, and choose MonoGame or KNI in Platform. Or run gumcli new MyGame --platform monogame (--platform kni for KNI). The game already references Gum, loads the Gum project and copies it to the output folder, so you can skip the rest of this page. See Creating a Project.
The rest of this page adds Gum to a game you already have.
Adding Gum NuGet Packages
The easiest way to add Gum to your project is to use NuGet. Open your project in your preferred IDE, or add packages through the command line. Each Gum NuGet package works on any platform. For example, MonoGame Desktop and Android project types use the same Gum NuGet package.
Add the Gum.MonoGame NuGet package (https://www.nuget.org/packages/Gum.MonoGame)
Modify csproj:
<PackageReference Include="Gum.MonoGame" Version="*" />Or add through command line:
dotnet add package Gum.MonoGameAdd the Gum.KNI NuGet package (https://www.nuget.org/packages/Gum.KNI)
Modify csproj:
<PackageReference Include="Gum.KNI" Version="*" />Or add through command line:
dotnet add package Gum.KNIAdd the Gum.FNA NuGet package (https://www.nuget.org/packages/Gum.FNA)
Modify csproj:
<PackageReference Include="Gum.FNA" Version="*" />Or add through command line:
dotnet add package Gum.FNAThe Game1 class in Adding Gum to Game needs only this package. Extra features come as separate packages, listed in Optional Extras.
Adding Source (Optional)
You can directly link your project to source instead of a NuGet package for improved debuggability, access to fixes and features before NuGet packages are published, or if you are interested in contributing.
To add source, first clone the Gum repository: https://github.com/vchelaru/Gum
If you have already added the Gum NuGet package to your project, remove it.
Add the following projects to your solution:
<Gum Root>/MonoGameGum/MonoGameGum.csproj
<Gum Root>/GumCommon/GumCommon.csproj
Next, add project references in your game project. Your project might look like this depending on the location of the Gum repository relative to your game project:
To link an extra from Optional Extras, add its project instead of its package:
Shapes: <Gum Root>/Runtimes/GumShapes/MonoGameGumShapes.csproj
KernSmith: <Gum Root>/Integrations/KernSmith/KernSmith.MonoGameGum/KernSmith.MonoGameGum.csproj (also add <Gum Root>/Integrations/KernSmith/KernSmith.GumCommon/KernSmith.GumCommon.csproj to the solution)
ShadowDusk: <Gum Root>/Runtimes/GumShadowDusk/MonoGameGum.ShadowDusk.csproj
Expressions: <Gum Root>/Runtimes/GumExpressions/GumExpressions.csproj
Add the following projects to your solution:
<Gum Root>/MonoGameGum/KniGum/KniGum.csproj
<Gum Root>/GumCommon/GumCommon.csproj
Next, add project references in your game project. Your project might look like this depending on the location of the Gum repository relative to your game project:
To link an extra from Optional Extras, add its project instead of its package:
Shapes: <Gum Root>/Runtimes/GumShapes/KniGumShapes.csproj
KernSmith: <Gum Root>/Integrations/KernSmith/KernSmith.KniGum/KernSmith.KniGum.csproj (also add <Gum Root>/Integrations/KernSmith/KernSmith.GumCommon/KernSmith.GumCommon.csproj to the solution)
ShadowDusk: <Gum Root>/Runtimes/GumShadowDusk/KniGum.ShadowDusk.csproj
Expressions: <Gum Root>/Runtimes/GumExpressions/GumExpressions.csproj
Add the following projects to your solution:
<Gum Root>/MonoGameGum/FnaGum/FnaGum.csproj
<Gum Root>/GumCommon/GumCommon.csproj
Next, add project references in your game project. Your project might look like this depending on the location of the Gum repository relative to your game project:
To link an extra from Optional Extras, add its project instead of its package:
ShadowDusk: <Gum Root>/Runtimes/GumShadowDusk/FnaGum.ShadowDusk.csproj
Expressions: <Gum Root>/Runtimes/GumExpressions/GumExpressions.csproj
If using Visual Studio Code, see the Visual Studio Code and Linking Source page.
Nez (Core)
If your game derives from Nez's Core instead of Game, use this class instead of the Game1 in the next section.
Adding Gum to Game
The following is a complete Game1 class. It needs only the base package and builds its UI in code, so it runs without a Gum project.
The button in the center of the window confirms Gum works. Delete it once you start building your game.
Optional Extras
Each extra is a separate package. Add the package, then add its line right after GumUI.Initialize.
Extra
MonoGame package
KNI package
FNA package
Line after Initialize
Shapes (Recommended): circle fill, rounded corners, gradient, drop shadow
Gum.Shapes.MonoGame
Gum.Shapes.KNI
none
GumUI.UseShapes();
KernSmith (Recommended): fonts built at runtime, no .fnt files
KernSmith.MonoGameGum
KernSmith.KniGum
none
GumUI.UseKernSmith();
ShadowDusk: .fx and .slang shader files
Gum.MonoGame.ShadowDusk
Gum.KNI.ShadowDusk
Gum.FNA.ShadowDusk
GumUI.UseShadowDusk();
Expressions: arithmetic in variable references
Gum.Expressions
Gum.Expressions
Gum.Expressions
GumUI.UseExpressions();
Shapes also needs the HiDef graphics profile. Add this line to the Game1 constructor, right after _graphics is created:
Loading Your Gum Project
To load a Gum project, pass its .gumj path to Initialize. The path is relative to the Content folder:
Then copy the Gum project to the output folder by adding this to your .csproj:
To create the Gum project, load it on Android or web, and show its screens, see Loading a Gum Project.
To start building UI, continue with the code-only Forms tutorial.
Last updated
Was this helpful?

