Generated Visual Studio SLN files do not work properly with Visual Studio Version Selector
Reproduced the problem on cmake version 3.16.0-rc3
just now.
If you use "Microsoft Visual Studio Version Selector" (under Right Click -> Open With) to open CMake generated .sln files, then they just open in the latest installed Visual Studio version. This happens despite which VS version you picked at generate time.
This is because the Version Selector needs an extra newline at the start of the file. Seems like it can't cope without it for some reason.
You can reproduce this difference by adding or removing that first newline at the very beginning the file. If you add this newline manually then you can see the change to the solution file's icon in the shell. It will switch from a versionless icon to an icon that has the Visual Studio version number that your generator targeted. If you remove it, the shell icon will revert to be versionless. This shell icon change also corresponds to the behavior in Version Selector, presumably using the same logic.
The repro applies to all CMake projects, but I'll go ahead and provide one here -
CMakeLists.txt:
cmake_minimum_required (VERSION 2.8.11)
project (HELLO)
add_executable (hello main.c)
main.c:
int main(int argc, char* argv[]) {
return 0;
}
Command line to generate project:
cd repro-dir
mkdir build
cd build
cmake -G "Visual Studio 15 2017" ..