【问题标题】:Failed to run MSBuild command to get the value of VCTargetsPath无法运行 MSBuild 命令获取 VCTargetsPath 的值
【发布时间】:2018-11-20 09:00:51
【问题描述】:

我在使用 cmake 生成 Visual Studio 项目时遇到此错误。对于上下文,我正在尝试在Exercism 上做一些练习(需要注册)。我已经在 VS 中安装了 v141(见下面的截图)。似乎是什么问题?

操作系统:Windows 10 CMake:3.12.4 提升:1.55.0 Visual Studio 企业版 2017 15.8.4

CMakeLists.txt

# Get the exercise name from the current directory
get_filename_component(exercise ${CMAKE_CURRENT_SOURCE_DIR} NAME)

# Basic CMake project
cmake_minimum_required(VERSION 2.8.11)

# Name the project after the exercise
project(${exercise} CXX)

# Locate Boost libraries: unit_test_framework, date_time and regex
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.59 REQUIRED COMPONENTS unit_test_framework date_time regex)

# Enable C++11 features on gcc/clang
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(GNU|Clang)")
    set(CMAKE_CXX_FLAGS "-std=c++11")
endif()

# Configure to run all the tests?
if(${EXERCISM_RUN_ALL_TESTS})
    add_definitions(-DEXERCISM_RUN_ALL_TESTS)
endif()

# Get a source filename from the exercise name by replacing -'s with _'s
string(REPLACE "-" "_" file ${exercise})

# Implementation could be only a header
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.cpp)
    set(exercise_cpp ${file}.cpp)
else()
    set(exercise_cpp "")
endif()

# Build executable from sources and headers
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h)

# We need boost includes
target_include_directories(${exercise} PRIVATE ${Boost_INCLUDE_DIRS})

# We need boost libraries
target_link_libraries(${exercise} ${Boost_LIBRARIES})

# Tell MSVC not to warn us about unchecked iterators in debug builds
if(${MSVC})
    set_target_properties(${exercise} PROPERTIES
        COMPILE_DEFINITIONS_DEBUG _SCL_SECURE_NO_WARNINGS)
endif()

# Run the tests on every build
add_custom_command(TARGET ${exercise} POST_BUILD COMMAND ${exercise})

错误

C:\Users\hurrjae\Exercism\cpp\hello-world>cmake -DBOOST_INCLUDEDIR:PATH="C:\Program Files\Boost\boost_1_55_0"
CMake Error at CMakeLists.txt:8 (project):
Failed to run MSBuild command:

    C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/MSBuild.exe

to get the value of VCTargetsPath:

    Microsoft (R) Build Engine version 15.8.168+ga8fba1ebd7 for .NET Framework
    Copyright (C) Microsoft Corporation. All rights reserved.

    Build started 20/11/2018 9:50:14 PM.
    Project "C:\Users\hurrjae\Exercism\cpp\hello-world\CMakeFiles\3.12.4\VCTargetsPath.vcxproj" on node 1 (default targets).
    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140\Microsoft.Cpp.Platform.targets(57,5): error MSB8020: The build tools for v141 (Platform Toolset = 'v141') cannot be found. To build using the v141 build tools, please install v141 build tools.  Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [C:\Users\hurrjae\Exercism\cpp\hello-world\CMakeFiles\3.12.4\VCTargetsPath.vcxproj]
    Done Building Project "C:\Users\hurrjae\Exercism\cpp\hello-world\CMakeFiles\3.12.4\VCTargetsPath.vcxproj" (default targets) -- FAILED.

    Build FAILED.

    "C:\Users\hurrjae\Exercism\cpp\hello-world\CMakeFiles\3.12.4\VCTargetsPath.vcxproj" (default target) (1) ->
    (PlatformPrepareForBuild target) ->
    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140\Microsoft.Cpp.Platform.targets(57,5): error MSB8020: The build tools for v141 (Platform Toolset = 'v141') cannot be found. To build using the v141 build tools, please install v141 build tools.  Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [C:\Users\hurrjae\Exercism\cpp\hello-world\CMakeFiles\3.12.4\VCTargetsPath.vcxproj]

        0 Warning(s)
        1 Error(s)

    Time Elapsed 00:00:00.18


Exit code: 1



-- Configuring incomplete, errors occurred!
See also "C:/Users/hurrjae/Exercism/cpp/hello-world/CMakeFiles/CMakeOutput.log".

CMakeOutput.log

The system is: Windows - 10.0.17134 - AMD64

【问题讨论】:

    标签: windows visual-c++ cmake msbuild


    【解决方案1】:

    您在报告中包含的错误消息包含您可以重新定位项目的建议,并告诉您如何操作。我已经成功了。或者,您可以安装错误消息中显示的 v141 构建工具,而不必重新定位。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-02
      • 2012-01-19
      • 1970-01-01
      相关资源
      最近更新 更多