Minimum C# version to build source

I’m having trouble finding documentation about a minimum version of C# to build from source. Is there a specific version documented somewhere? I was thinking of contributing and didn’t want to use C#6 or even the latest C#7 features if that was against the MonoGame coding standards.

Thanks

Any recent version of C# should be able to successfully compile Monogame 3.5 or 3.6. This means that either VS 2015 or VS 2017 should work fine (Community Editions if you do not have an MSDN Professional Subscription).

When you download the source code you should be able to open the Project Properties windows, which will tell you what .NET Framework the solution is compiled for. My own suspicion since I have not looked at the source code is that it would be compiled against version 4.6 of the .NET Framework.

The versions of C# you are asking about are determined by the framework in use. Thus, if you install VS 2017 but compile to the 4.5 version of the .NET Framework, that is the C# version that will be generated for you in terms of your executable and assemblies…

The latest framework is 4.7, which has just been released and is installed with VS 2017 (I believe…). If you compile to this version of the framework than you will be using the latest version of C#.

If you would like to query the Monogame developers about this in real-time, simply go to the following link…

Scroll down to the bottom of the page and select “Chat Live” under the “Helpful Links” section…

Thanks for you answer. I wasn’t too concerned about Framework version. I assume that whatever version of the Framework their projects target is the version that they want to support. I also know that you can use most newer C# features while still targeting older Framework versions since the new features are often syntax sugar. I just didn’t want to get into a situation where I have a PR using C#6/7 features that then have to be changed because the maintainers don’t want to force people to use VS2015/2017 to build from source.

I’ll check out the GitHub link you provided.

Thanks for wanting to contribute! MonoGame currently uses C#5, so newer language features will fail to compile on the build bots. If you run into issues, try the Gitter chat. There are usually some MG devs on there that can help you out (most of the time quicker than on the forum).

Just in case you’re unaware, you can still use VS2017 and have lastest .net framework installed on your machine, but change the project to only build using the C#5 language, so if you use any of the new stuff, then when you build locally it will fail.

To do this:

Select the project and right click, select properties,
Go to the BUILD tab and click the advanced button (bottom right)
On the “Advanced Build Settings” change the “Language Version:” dropdown from Default to C’ 5.0.
Click ok and save, then build your project.

Note, you will have to do this for all your projects - hopefully if it’s downloaded from git it should ideally already be set.

It will not be set. I think Protobuild does not currently support setting the language version. At least it’s not in the MG build files. @hachque?

Very cool. I was unaware of that project setting. It doesn’t appear as if the generated projects from Protobuild use that particular setting, but it could be worth including in order to ensure contributors are using the correct version.

Yeah, I remember it came up before, but since we didn’t change it back then, I think Protobuild doesn’t (didn’t?) support it.

@Jjagg Thanks for the info on Protobuild, never actually used that so wasn’t aware - though locally it should help the OP to not use the new language changes.

Protobuild does support setting the language version. The property you’re looking for is LangVersion.

MonoGame actually already sets it, but it sets it to Default. Normally we use this logic:

        <xsl:when test="$root/Input/Properties/LangVersion">
          <LangVersion>
            <xsl:value-of select="$root/Input/Properties/LangVersion"/>
          </LangVersion>
        </xsl:when>
        <xsl:when test="$root/Input/Generation/Platform = 'Unity'">
          <LangVersion>4</LangVersion>
        </xsl:when>
        <xsl:when test="$root/Input/Generation/Platform = 'WindowsPhone81' or $root/Input/Generation/Platform = 'Windows8'">
          <LangVersion>5</LangVersion>
        </xsl:when>
        <xsl:otherwise>
          <LangVersion>6</LangVersion>
        </xsl:otherwise>

This maps language version to the highest support version for any given platform, based on the framework that platform targets by default. If you change the LangVersion, you may also need to change the targeted framework.