简体   繁体   中英

How do you set the language version for C# projects when generating projects with 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?

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM