Using C# 8 features with MonoGame?

I’ve currently got a game (working in UWP, OpenGL, & Android) that I started with the templates from the MonoGame 3.7.1 official build, originally using Visual Studio 2017, & upgraded to Visual Studio 2019 a while back. I’d like to use C# 8 language features if possible, but I’m a bit confused on what I’d need to do (or if it’s even possible).

VS docs suggest that the compiler version depends on the target framework, with only .NET Core 3+ or .NET Standard 2.1+ getting C# 8. From what I understand, MonoGame’s template projects target .NET Framework 4.5 (default) to 4.7 (newest), which only supports C# 7.3.

Is it currently possible to build a MonoGame project that targets .NET Core 3? Or is there some other way of changing the compiler to use C# 8 features? Thanks for any help you can give!

(I admit that I’m not particularly familiar with Windows / .NET projects in general, having spent most of my professional-coding life targeting Linux :))

1 Like

You could build MonoGame that targets .NET Core 3, just go on their github and pull the develop branch, it targets .NET Core 3.
Look:

1 Like

Ya there is actually a dev installer still its about a month old i think.

Just have to dig around for it aka scroll down on the git hub page.
find package windows find the last successful build and click artifacts.

http://teamcity.monogame.net/viewLog.html?buildId=92769&buildTypeId=MonoGame_PackagingWindows&tab=artifacts

I think after this it will all be using nuget or something i dunno exactly.
They are trying to prep for a change towards core3 and other stuff i think.

I started with three projects in solution, Android, .NET Core 3.0 and shared library for the code and C# 8 worked. Now switched the shared project to .NET Standard 2.1 library and it works too. So it’s definitely possible.

In case anyone from the future finds this thread: if you have an existing project based on the MonoGame 3.7 templates and want to use C# 8 in the easiest manner possible (without the need to change framework versions), just open your project’s .csproj file and add this to the main <PropertyGroup> defining that project’s build:

<LangVersion>8.0</LangVersion>
or
<LangVersion>latest</LangVersion>

3 Likes