Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# CMake发电在VS 2019 C项目中失败_C#_Cmake_Visual Studio 2019 - Fatal编程技术网

C# CMake发电在VS 2019 C项目中失败

C# CMake发电在VS 2019 C项目中失败,c#,cmake,visual-studio-2019,C#,Cmake,Visual Studio 2019,使用VS 2019,我的CMake CSharp项目抱怨: 启用语言后未设置CMAKE_CSharp_编译器 及 目前,Microsoft Visual Studio 2010及更高版本仅支持C 一代又一代。已使用以下文件: CMakeLists.txt: cmake_minimum_required(VERSION 3.1) project(test_proj CSharp) include(CSharpUtilities) set(CMAKE_CSharp_FLAGS "/langvers

使用VS 2019,我的CMake CSharp项目抱怨:

启用语言后未设置CMAKE_CSharp_编译器 及

目前,Microsoft Visual Studio 2010及更高版本仅支持C 一代又一代。已使用以下文件:

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": []
    }
  ]
}

问题似乎与忍者生成器有关。

错误消息描述了此功能不工作的原因:

目前,Microsoft Visual Studio 2010及更高版本仅支持C。 这是因为只有选择Microsoft Visual Studio 2010或更高版本的生成器时,CMake才支持C。以下是他们发布其C支持时从CMake网站获得的信息:

CMake学会了支持CSharp C作为一种一流的语言,可以通过项目和enable_语言命令来启用。目前,VS 2010及更高版本的Visual Studio生成器支持它

在撰写本文时,最新版本的CMake仍然是这样,它不能与忍者生成器一起工作。只需将发电机更改为VS 2019:

{
  "configurations": [
    {
      "name": "x64-Release",
      "generator": "Visual Studio 16 2019",
      ...

我测试您的解决方案生成器:Visual Studio 16 2019,但另一个错误显示:无法创建命名生成器Visual Studio 16 2019 Win64!我不明白为什么VS会将Win64添加到生成器中。我的CMake版本是3.14。从VS 16.0更新到16.3.6解决使用生成器时的问题:Visual Studio 16 2019 Win64