使用VS 2019,我的CMake CSharp项目抱怨:
CMAKE_CSharp_COMPILER not set, after EnableLanguage
和
C# is currently only supported for Microsoft Visual Studio 2010 and later
生成后。已使用以下文件:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.1)
project(test_proj CSharp)
include(CSharpUtilities)
set(CMAKE_CSharp_FLAGS "/langversion:latest")
add_executable("test"
main.cs
)
set_target_properties("test" PROPERTIES
LINKER_LANGUAGE CSharp
VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.5"
VS_DOTNET_REFERENCES
"Microsoft.CSharp;
System;
System.Core;
System.Data;
System.Data.DataSetExtensions"
)
CMakeSettings.json:
{
"configurations": [
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "Release",
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ],
"variables": []
}
]
}
问题似乎与Ninja
生成器有关。
答案 0 :(得分:0)
错误消息描述了为什么它不起作用:
C# is currently only supported for Microsoft Visual Studio 2010 and later.
这是因为,如果您将生成器选择为Microsoft Visual Studio 2010或更高版本,则CMake仅支持C# 。这是CMake网站上发布C#支持时的documentation:
CMake学会了支持CSharp(C#)作为一流语言,可以通过
project()
和enable_language()
命令启用。 Visual Studio Generators for VS 2010及更高版本当前支持它。
在撰写本文时,最新版本的CMake仍然是这种情况,并且它不适用于Ninja生成器。只需将生成器更改为VS 2019:
{
"configurations": [
{
"name": "x64-Release",
"generator": "Visual Studio 16 2019",
...