Version 3.8 of CMake supports generating Visual Studio C# projects. By default, it sets the language version ("LangVersion") to version 3 in the .csproj file. I need to change to a more recent language version, like version 6.
How do I override the language version in my CMakeLists.txt
file?
As of July 2022, the most recent stable version of the language is C# 10.0, which was released in 2021 in .NET 6.0.
If you're using the latest version of Visual Studio 2019, C#, you may not see the option to change the C# language version of your project. This is a new change in Visual Studio 2019/. NET Core 3.0. The new C# compiler chooses the default version based on your .
You can set this as a compile flag on a target:
project(MyProject CSharp)
add_executable(MyExe main.cs)
target_compile_options(MyExe PRIVATE "/langversion:6")
Alternatively, you can set the global variable, to apply it to all future targets:
set(CMAKE_CSharp_FLAGS "/langversion:6")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With