vs2022 - Create A Visual Basic MonoGame Project

If you are a Visual Basic (.net) programmer, here is a way to get started in MonoGame:

This information was adapted from this excellent video from Two-Bit Coding
TwoBitCoding


STEP 1

Start Visual Studio 2022

Create A New Console Project in Visual Basic

DELETE ALL CODE IN Program.vb

REPLACE WITH
'================================== START COPY AFTER THIS LINE

Imports MyProjectName '<==== CHANGE TO THE NAME OF YOUR PROJECT
Public Module Program
Sub Main()
Using game As New Game1()
game.Run()
End Using
End Sub
End Module
'----------------------------- END OF CODE ADDED TO Program.vb (DO NOT COPY THIS LINE)



STEP 2

IN SOLUTION, RIGHT-CLICK Dependencies

SELECT Manage NuGet Packages

IN NuGet Package Manager SELECT BROWSE

IN Search BOX ADD

MonoGame

SELECT MonoGame.Framework.DesktopGL

AND DOWNLOAD IT TO THE PROJECT

SELECT MonoGame.Content.Builder.Task

AND DOWNLOAD IT TO THE PROJECT

CLOSE NuGet Package Manager



STEP 3

IN VS 2022 CREATE MODULE AND NAME IT
Game1.vb

DELETE ALL CODE IN MODULE Game1

AND ADD THIS
'================================== START COPY AFTER THIS LINE
Imports System
Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Graphics
Imports Microsoft.Xna.Framework.Input

Namespace MyProjectName.MyProjectName '<==== CHANGE TO THE NAME OF YOUR PROJECT

Public Class Game1

    Inherits Microsoft.Xna.Framework.Game


    Public Sub New()

        '   Create the Graphics Device Manager
        gdm = New GraphicsDeviceManager(Me)
        '
        '
        '   CONTENT MANAGER
        Content.RootDirectory = "Content"
        '
        '   SET BOTH TO TRUE FOR 60 FRAMES PER SECOND (FPS) 
        gdm.SynchronizeWithVerticalRetrace = True
        IsFixedTimeStep = True
        '
        '   WINDOW RESIZE
        Window.AllowUserResizing = False
        '
        '	Turn the mouse off  (SET TO True IF YOU WANT MOUSE)
        IsMouseVisible = False

        '   FULL SCREEN
        '   **** DO NOT SET THIS TO True
       '   BEFORE KEYBOARD INPUTS HAVE BEEN ADDED TO YOUR PROJECT ****
        gdm.IsFullScreen = False


    End Sub


    Protected Overrides Sub Initialize()
        MyBase.Initialize()
    End Sub


    Protected Overrides Sub LoadContent()

        '   Load FONTS
        MainFont = Content.Load(Of SpriteFont)("Arial20")

        '   Create SriteBatch
        SB = New SpriteBatch(GraphicsDevice)

    End Sub

    Protected Overrides Sub UnloadContent()

    End Sub


    Protected Overrides Sub Update(ByVal gameTime As GameTime)

    End Sub



    Protected Overrides Sub Draw(ByVal gameTime As GameTime)

        GraphicsDevice.Clear(Color.CornflowerBlue)

        SB.Begin()
	
	SB.DrawString(MainFont, "Woo Hoo! New MonoGame Project In VB.net.", New Vector2(0,0), Color.White)

        SB.End()

    End Sub

End Class

End Namespace '<-- THIS MUST ALSO BE COPIED

------------------------ END OF CODE COPIED INTO Game1.vb (DO NOT COPY THIS LINE)



STEP 4

CREATE NEW MODULE Globals.vb

DELETE ALL CODE AND ADD THIS

'================================== START COPY AFTER THIS LINE
Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Graphics

Module Globals

Public gdm As GraphicsDeviceManager
Public SB As SpriteBatch

'SPRITEFONTS
Public MainFont As SpriteFont

End Module

---------------------------END OF CODE COPIED INTO Globals.vb



STEP 5

CHANGE FROM CONSOLE PROJECT

RIGHT-CLICK ProjectName AND SELECT PROPERTIES

UNDER APPLICTION TAB

IN APPLICATION TYPE
CHANGE FROM Console Application TO Windows Application

IN STARTUP OBJECT
SELECT Sub Main

(OPTIONAL) UNDER COMPILE TAB
CHANGE Option Strict Off TO Option Strict On



STEP 6

ADD CONTENT FOLDER

IN PROJECT SOLUTION RIGHT-CLICK ProjectName

SELECT Add Folder AND NAME THE FOLDER Content



STEP 7

CLICK WINDOWS START BUTTON AND OPEN THE MonoGame Content Builder APPLICATION MGCB Editor

IN MGCB EDITOR SELECT New

BROWSE UNTIL THE Content FOLDER CAN BE SELECTED. THE CONTENT FOLDER WILL BE IN THE
PROJECT FOLDER SOMEWHERE

SELECT FOLDER Content

CLICK Open BUTTON

BUTTON CHANGES TO Save

IN File Name TEXT BOX ADD Content

CLICK Save BUTTON

CLICK Build ICON IN MGCB EDITOR

RIGHT-CLICK Content IN Project SECTION OF MGCB EDITOR Add → New Item

New File WINDOW POPS UP

SELECT SpriteFontDescription (.spritefont)
In Name TEXTBOX ENTER: Arial20
CLICK Create BUTTON



STEP 8

IN VISUAL STUDIO PROJECT SOLUTION Content FOLDER
DOUBLE-CLICK Arial20.spritefont

IN Arial20.spritefont XML FILE CHANGE

12 TO 20

SAVE PROJECT AND CLOSE Arial20.spritefont XML FILE IN VISUAL STUDIO

IN MGCB EDITOR

CLICK Build ICON TO BUILD THE CHANGE MADE TO FONT SIZE.



STEP 9

IN VISUAL STUDIO 2022

Run PROJECT

THE CORNFLOWER BLUE SCREEN SHOULD APPEAR


Summary

This text will be hidden

Two things…
First … note that there are two errors … I switched something. Sorry abou that.

In Step 1
Imports MyProjectName SHOULD BE Imports MyProjectName.MyProjectName

In Step 3
NameSpace MyProjectName.MyProjectName SHOULD BE Namespace MyProjectName

Second … this method DOES NOT WORK if you install the latest version of:
MonoGame.Content.Builder.Task

In the Install section there is a drop-down list with the latest stable build already selected. Drop the list and select:
MonoGame.Content.Builder.Task v 3.8.0.1641

That version will work. The latest version creates a Content path that somehow follows the .net Core 6 path. And I could not figure out how to solve it. So I just went back to the one that I know works.

If someone gets a solution to this issue, please tell me here.

Thanks,
HMdesigner