How To Setup MonoGame for F#

There are little to NO guides on using F# with MonoGame..
well that’s bit of an over statement there are a few on the internet but they are either outdated or just don’t work at all.

So I got to work and figured out how to setup an F# project to use …


This content originally appeared on DEV Community and was authored by SabeDoesThings

There are little to NO guides on using F# with MonoGame..
well that's bit of an over statement there are a few on the internet but they are either outdated or just don't work at all.

So I got to work and figured out how to setup an F# project to use MonoGame! There are probably other ways to do it but this way worked for me and I want to show how other people can do it too.

So let's get started!

Start by creating a new F# console project.

dotnet new console -lang F# -o <ProjectName>
cd <ProjectName>

Add the MonoGame Framework

dotnet add package MonoGame.Framework.DesktopGL

Create Game1.fs

Game1.fs

namespace <Project Name>

open Microsoft.Xna.Framework
open Microsoft.Xna.Framework.Graphics
open Microsoft.Xna.Framework.Input

type Game1() as this =
    inherit Game()

    let graphics = new GraphicsDeviceManager(this)
    let mutable spriteBatch: SpriteBatch = null

    do
        this.Content.RootDirectory <- "Content"
        this.IsMouseVisible <- true

    override _.Initialize() =
        // TODO: Add your initialization logic here

        base.Initialize()

    override _.LoadContent() =
        spriteBatch <- new SpriteBatch(this.GraphicsDevice)

        // TODO: use this.Content to load your game content here

    override _.Update(gameTime: GameTime) =
        let kstate = Keyboard.GetState()
        if kstate.IsKeyDown Keys.Escape then
            this.Exit()

        // TODO: Add your update logic here

        base.Update gameTime

    override _.Draw(gameTime: GameTime) =
        this.GraphicsDevice.Clear Color.CornflowerBlue

        spriteBatch.Begin()
        // TODO: Add your drawing code here
        spriteBatch.End()

        base.Draw gameTime

Add to Program.fs file

open <Project Name>

[<EntryPoint>]
let main argv =
    use game = new Game1()
    game.Run()
    0

the .fsproj file should look like this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="Game1.fs" />
    <Compile Include="Program.fs" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.4.1" />
  </ItemGroup>

</Project>

Adding Content.mgcb

Create folder called "Content"

Add dotnet tools

dotnet new tool-manifest
dotnet tool install dotnet-mgcb
dotnet tool install dotnet-mgcb-editor
dotnet tool install dotnet-mgcb-editor-windows
dotnet tool install dotnet-mgcb-editor-linux
dotnet tool install dotnet-mgcb-editor-mac

Open MGCB Editor

First you have to have it installed

dotnet tool install -g dotnet-mgcb
dotnet tool install -g dotnet-mgcb-editor

Next in a command line in your directory use this command

dotnet tool restore
mgcb-editor

Generate the Content.mgcb file

Once you are inside the MGCB Editor do
File -> New
Go to your directory inside of the Content folder and name the file "Content.mgcb"

Done!

You should now have the Content file and are able to build assets for you're games.


This content originally appeared on DEV Community and was authored by SabeDoesThings


Print Share Comment Cite Upload Translate Updates
APA

SabeDoesThings | Sciencx (2025-11-07T12:45:44+00:00) How To Setup MonoGame for F#. Retrieved from https://www.scien.cx/2025/11/07/how-to-setup-monogame-for-f/

MLA
" » How To Setup MonoGame for F#." SabeDoesThings | Sciencx - Friday November 7, 2025, https://www.scien.cx/2025/11/07/how-to-setup-monogame-for-f/
HARVARD
SabeDoesThings | Sciencx Friday November 7, 2025 » How To Setup MonoGame for F#., viewed ,<https://www.scien.cx/2025/11/07/how-to-setup-monogame-for-f/>
VANCOUVER
SabeDoesThings | Sciencx - » How To Setup MonoGame for F#. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/11/07/how-to-setup-monogame-for-f/
CHICAGO
" » How To Setup MonoGame for F#." SabeDoesThings | Sciencx - Accessed . https://www.scien.cx/2025/11/07/how-to-setup-monogame-for-f/
IEEE
" » How To Setup MonoGame for F#." SabeDoesThings | Sciencx [Online]. Available: https://www.scien.cx/2025/11/07/how-to-setup-monogame-for-f/. [Accessed: ]
rf:citation
» How To Setup MonoGame for F# | SabeDoesThings | Sciencx | https://www.scien.cx/2025/11/07/how-to-setup-monogame-for-f/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.