Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you set the language version for C# projects when generating projects with CMake?

Tags:

c#

cmake

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?

like image 259
Michael Kelley Avatar asked Mar 01 '17 02:03

Michael Kelley


People also ask

What is current C# version?

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.

Why can't I select a different C# version?

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 .


1 Answers

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")
like image 140
MuertoExcobito Avatar answered Oct 21 '22 23:10

MuertoExcobito