I have a C# project which specifies the target framework but not the language version. Is there any documentation which specifies what language version will be chosen for any given target framework version? Also does the version of the SDK in use matter if the targeted framework is lower -- e.g. in my case, I am using .NET Core SDK 2.2 but the project targets netcoreapp2.1, would I get the same language version as if I was using SDK 2.1 targeting netcoreapp2.1? I'm currently getting a compilation error which states "Please use language version 7.2 or greater to allow ..." so I conclude 1) the default version is less than 7.2, and 2) the tooling supports or at least is aware of 7.2.
I found https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version states:
The C# compiler determines a default language version based on your project's target framework or frameworks. When your project targets a preview framework that has a corresponding preview language version, the language version used is the preview language version. When your project doesn't target a preview framework, the language version used is the latest minor version.
For example, during the preview period for .NET Core 3.0, any project that targets netcoreapp3.0 or netstandard2.1 (both in preview) will use the C# 8.0 language (also in preview). Projects targeting any released version will use C# 7.3 (the latest released version). This behavior means that any project targeting .NET Framework will use latest (C# 7.3).
There must be more to it than that, since the sentence " When your project doesn't target a preview framework, the language version used is the latest minor version." would mean to me that it should be using at least 7.2. Unless "latest minor version" really means latest minor version for the given targeted framework in which case I'd like to see a table somewhere that lists those (something like 2.1 -> 7.1, 2.2 -> 7.3, etc.).
After writing all of the above, I added <LangVersion>latest</LangVersion>
to my csproj and it now compiles. I had been under the impression that the default for language version was "latest", but obviously that is not the case.