VS: Minor toolset version selection breaks for toolset 14.36 and above
EDIT: This is caused by VS Developer Community feedback item 10385615
Reproduction
- CMake 3.27.1
- Visual Studio Professional 2022 17.7.1
CMakeLists.txt
cmake_minimum_required(VERSION 3.27.1)
project(minimal)
$ cmake -T "version=14.37.32822" -B ./build/ -S ./
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
No CMAKE_C_COMPILER could be found.
CMake Error at CMakeLists.txt:2 (project):
No CMAKE_CXX_COMPILER could be found.
-- Configuring incomplete, errors occurred!
Investigation
Looking into this further I found the issue seemed to be related to events like the following in CMakeConfigureLog.yaml
---
events:
-
kind: "message-v1"
backtrace:
- "C:/Program Files/CMake/share/cmake-3.27/Modules/CMakeDetermineSystem.cmake:211 (message)"
- "CMakeLists.txt:2 (project)"
message: |
The system is: Windows - 10.0.19045 - AMD64
-
kind: "message-v1"
backtrace:
- "C:/Program Files/CMake/share/cmake-3.27/Modules/CMakeDetermineCompilerId.cmake:17 (message)"
- "C:/Program Files/CMake/share/cmake-3.27/Modules/CMakeDetermineCompilerId.cmake:64 (__determine_compiler_id_test)"
- "C:/Program Files/CMake/share/cmake-3.27/Modules/CMakeDetermineCCompiler.cmake:123 (CMAKE_DETERMINE_COMPILER_ID)"
- "CMakeLists.txt:2 (project)"
message: |
Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler:
Build flags:
Id flags:
The output was:
1
MSBuild version 17.7.2+d6990bcfa for .NET Framework
Build started 17/08/2023 12:47:15 PM.
Project "C:\\Users\\gerard\\Desktop\\temp\\build\\CMakeFiles\\3.27.1\\CompilerIdC\\CompilerIdC.vcxproj" on node 1 (default targets).
C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\VC\\Auxiliary\\Build\\14.37.17.7\\Microsoft.VCToolsVersion.14.37.17.7.props(3,3): error MSB4019: The imported project "C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\VC\\Auxiliary\\Build\\14.37.17.7\\Microsoft.VCRedistVersion.default.props" was not found. Confirm that the expression in the Import declaration "C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\VC\\Auxiliary\\Build\\14.37.17.7\\Microsoft.VCRedistVersion.default.props" is correct, and that the file exists on disk. [C:\\Users\\gerard\\Desktop\\temp\\build\\CMakeFiles\\3.27.1\\CompilerIdC\\CompilerIdC.vcxproj]
Done Building Project "C:\\Users\\gerard\\Desktop\\temp\\build\\CMakeFiles\\3.27.1\\CompilerIdC\\CompilerIdC.vcxproj" (default targets) -- FAILED.
Build FAILED.
"C:\\Users\\gerard\\Desktop\\temp\\build\\CMakeFiles\\3.27.1\\CompilerIdC\\CompilerIdC.vcxproj" (default target) (1) ->
C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\VC\\Auxiliary\\Build\\14.37.17.7\\Microsoft.VCToolsVersion.14.37.17.7.props(3,3): error MSB4019: The imported project "C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\VC\\Auxiliary\\Build\\14.37.17.7\\Microsoft.VCRedistVersion.default.props" was not found. Confirm that the expression in the Import declaration "C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\VC\\Auxiliary\\Build\\14.37.17.7\\Microsoft.VCRedistVersion.default.props" is correct, and that the file exists on disk. [C:\\Users\\gerard\\Desktop\\temp\\build\\CMakeFiles\\3.27.1\\CompilerIdC\\CompilerIdC.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.04
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\14.37.17.7\Microsoft.VCToolsVersion.14.37.17.7.props
contains the following
<?xml version = "1.0" encoding="utf-8"?>
<Project ToolsVersion = "4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)Microsoft.VCRedistVersion.default.props))"/>
<PropertyGroup>
<VCToolsVersion Condition = "'$(VCToolsVersion)' == ''" >14.37.32822</VCToolsVersion>
</PropertyGroup>
</Project>
and as expected C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\14.37.17.7\
doesn't have a Microsoft.VCRedistVersion.default.props
The only Microsoft.VCRedistVersion.default.props
I found was at C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\Microsoft.VCRedistVersion.default.props
with the following
<?xml version = "1.0" encoding="utf-8"?>
<Project ToolsVersion = "4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VCToolsRedistVersion Condition = "'$(VCToolsRedistVersion)' == ''" >14.36.32532</VCToolsRedistVersion>
</PropertyGroup>
</Project>
Workaround
Modifying the relevant Microsoft.VCToolsVersion.*.props
with the following
- <Import Project="$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)Microsoft.VCRedistVersion.default.props))"/>
+ <Import Project="$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)/../Microsoft.VCRedistVersion.default.props))"/>
But as you can imagine this isn't really an acceptable workaround.
Summary
The CompilerIdC.vcxproj
directory is malformed and can't import the necessary .props
.
Skimming through Side-by-side minor version MSVC toolsets in Visual Studio 2017 It looks like the expectation is that the Microsoft.VCToolsVersion.*.props
are supposed to be copied around and not used in place as C:\Users\gerard\Desktop\temp\build\CMakeFiles\3.27.1\CompilerIdC\CompilerIdC.vcxproj
does currently.