microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.46k stars 449 forks source link

Visual Studio 2015 Kits doesn't work if installed via newer Visual Studio Build Tools. #1381

Closed sarunint closed 2 days ago

sarunint commented 4 years ago

Brief Issue Summary

I've installed VS2015 Build Tools via the latest version of Visual Studio Installer.

It is known that VS2015 Build Tools that is installed with newer VS installer will not have its shortcuts working correctly (including it's vcvarsall.bat).

The correct way to load up VS2015 Build Tools into a command prompt is to load using VS2017/9's vcvarsall.bat with argument vcvars_ver.

Expected:

  1. Load VS2015 kit
  2. Reconfigure the project
  3. The project should be successfully configured.

Apparent Behavior:

  1. Load VS2015 kit
  2. Reconfigure the project
  3. CMake Tools errors.

CMake Tools Log

[main] Configuring folder: test_cmake 
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -Hc:/Users/Sarun/dev/test_cmake -Bc:/Users/Sarun/dev/test_cmake/build -G "Visual Studio 14 2015" -T host=x64 -A x64
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Selecting Windows SDK version 10.0.14393.0 to target Windows 10.0.19041.
[cmake] CMake Error at CMakeLists.txt:3 (project):
[cmake]   Failed to run MSBuild command:
[cmake] 
[cmake]     MSBuild.exe
[cmake] 
[cmake]   to get the value of VCTargetsPath:
[cmake] 
[cmake]     Microsoft (R) Build Engine version 4.8.4084.0
[cmake]     [Microsoft .NET Framework, version 4.0.30319.42000]
[cmake]     Copyright (C) Microsoft Corporation. All rights reserved.
[cmake]     
[cmake]     Build started 22/07/2020 18:19:59.
[cmake]     Project "C:\Users\Sarun\dev\test_cmake\build\CMakeFiles\3.18.0\VCTargetsPath.vcxproj" on node 1 (default targets).
[cmake]     C:\Users\Sarun\dev\test_cmake\build\CMakeFiles\3.18.0\VCTargetsPath.vcxproj(15,2): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
[cmake]     Done Building Project "C:\Users\Sarun\dev\test_cmake\build\CMakeFiles\3.18.0\VCTargetsPath.vcxproj" (default targets) -- FAILED.
[cmake]     
[cmake]     Build FAILED.
[cmake]     
[cmake]     "C:\Users\Sarun\dev\test_cmake\build\CMakeFiles\3.18.0\VCTargetsPath.vcxproj" (default target) (1) ->
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "C:/Users/Sarun/dev/test_cmake/build/CMakeFiles/CMakeOutput.log".
[cmake]       C:\Users\Sarun\dev\test_cmake\build\CMakeFiles\3.18.0\VCTargetsPath.vcxproj(15,2): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
[cmake]     
[cmake]         0 Warning(s)
[cmake]         1 Error(s)
[cmake]     
[cmake]     Time Elapsed 00:00:00.24
[cmake]     
[cmake] 
[cmake]   Exit code: 1
[cmake] 
[cmake] 
[cmake] 

The cmake log is identical to what happens when I use VS2015's vcvarsall.bat.

Developer Tools Log

I only provided the relevant bit here.

varsForVSInstallation path:'C:\Program Files (x86)\Microsoft Visual Studio 14.0\' version:14.0 host arch:x64 - target arch:x64
[debug] [kit] OK running C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat amd64, env vars: [["CL",""],["_CL_",""],["INCLUDE","C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\INCLUDE;C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\ATLMFC\\INCLUDE;C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.14393.0\\ucrt;C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.14393.0\\shared;C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.14393.0\\um;C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.14393.0\\winrt;"],["LIBPATH","C:\\WINDOWS\\Microsoft.NET\\Framework64\\v4.0.30319;C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\LIB\\amd64;C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\ATLMFC\\LIB\\amd64;C:\\Program Files (x86)\\Windows Kits\\10\\UnionMetadata;C:\\Program Files (x86)\\Windows Kits\\10\\References;\\Microsoft.VCLibs\\14.0\\References\\CommonConfiguration\\neutral;"],["LINK",""],["_LINK_",""],["LIB","C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\LIB\\amd64;C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\ATLMFC\\LIB\\amd64;C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.14393.0\\ucrt\\x64;C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.14393.0\\um\\x64;"],["PATH","C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\amd64;C:\\WINDOWS\\Microsoft.NET\\Framework64\\v4.0.30319;C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE;C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Tools;C:\\Program Files (x86)\\HTML Help Workshop;C:\\Program Files (x86)\\Windows Kits\\10\\bin\\x64;C:\\Program Files (x86)\\Windows Kits\\10\\bin\\x86;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance Toolkit\\;C:\\Program Files (x86)\\gnupg\\bin;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\xampp\\php;C:\\ProgramData\\ComposerSetup\\bin;C:\\Program Files\\nodejs\\;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files (x86)\\Yarn\\bin\\;D:\\AndroidSDK\\platform-tools;D:\\Program Files\\Android\\Android Studio\\jre\\bin;C:\\Program Files\\Git\\cmd;C:\\Users\\Sarun\\AppData\\Local\\Microsoft\\WindowsApps;;C:\\Users\\Sarun\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Program Files\\LLVM\\bin;C:\\Program Files\\CMake\\bin"],["TMP","C:\\Users\\Sarun\\AppData\\Local\\Temp"],["FRAMEWORKDIR","C:\\WINDOWS\\Microsoft.NET\\Framework64"],["FRAMEWORKDIR64","C:\\WINDOWS\\Microsoft.NET\\Framework64"],["FRAMEWORKVERSION","v4.0.30319"],["FRAMEWORKVERSION64","v4.0.30319"],["UCRTCONTEXTROOT",""],["UCRTVERSION","10.0.14393.0"],["UNIVERSALCRTSDKDIR","C:\\Program Files (x86)\\Windows Kits\\10\\"],["VCINSTALLDIR","C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\"],["VCTARGETSPATH",""],["WINDOWSLIBPATH","C:\\Program Files (x86)\\Windows Kits\\10\\UnionMetadata;C:\\Program Files (x86)\\Windows Kits\\10\\References"],["WINDOWSSDKDIR","C:\\Program Files (x86)\\Windows Kits\\10\\"],["WINDOWSSDKLIBVERSION","10.0.14393.0\\"],["WINDOWSSDKVERSION","10.0.14393.0\\"],["VISUALSTUDIOVERSION","14.0"]]

This shows that the CMake Tools is using the vcvarsall.bat that came with VS2015 Build Tools (C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat) instead of the modern vcvarsall.bat (In my case, it is at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat).

Platform and Versions

Other Notes/Information

I've narrowed down the code that should be change. I think.

https://github.com/microsoft/vscode-cmake-tools/blob/d53c266c9b0bb43a2b1ca3d68c04de49fe5fc717/src/kit.ts#L672-L676

hamaney commented 3 years ago

any updates on this?

pborsutzki commented 3 years ago

I just found a workaround for this, as I am facing the same problem: Create a batch file that sets up your build environment. I called it env.bat and for me it looks like this:

call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 -vcvars_ver=14.16

Then setup a custom CMake-Kit by editing your %localappdata%\CMakeTools\cmake-tools-kits.json (open using Command Palette: > CMake: Edit User-Local Cmake Kits) and add your own kit. You can copy an existing Kit, but I had to remove some Visual Studio specifics ("visualStudio" and "visualStudioArchitecture") to get it working without errors. As I am trying to use ninja for building, I changed the generator to Ninja. If you want to stay with MSBuild, you probably should keep the generator from the kit you copied. The "keep": true in there makes the new entry persist in case you scan for kits again. So here is mine:

[
  {
    "name": "Visual Studio Professional 2017 Release - x86_amd64",
    "environmentSetupScript": "path\\to\\your\\env.bat",
    "keep": true,
    "preferredGenerator": {
      "name": "Ninja"
    }
  }
]

Then save the file. I immediately got some errors about json parsing failing:

[kit] Failed to parse cmake-tools-kits.json: 
    SyntaxError: Unexpected EOF at line 1 column 2 of the JSON5 data. Still to read: ""
    at error (c:\Users\<snip>\.vscode-server\extensions\ms-vscode.cmake-tools-1.6.0\dist\main.js:20167:25)
    at word (c:\Users\<snip>\.vscode-server\extensions\ms-vscode.cmake-tools-1.6.0\dist\main.js:20504:13)
    at value (c:\Users\<snip>\.vscode-server\extensions\ms-vscode.cmake-tools-1.6.0\dist\main.js:20604:56)
    at Object.parse (c:\Users\<snip>\.vscode-server\extensions\ms-vscode.cmake-tools-1.6.0\dist\main.js:20619:18)
    at Object.readKitsFile (c:\Users\<snip>\.vscode-server\extensions\ms-vscode.cmake-tools-1.6.0\dist\main.js:9318:26)
    at async Function.readUserKits (c:\Users\<snip>\.vscode-server\extensions\ms-vscode.cmake-tools-1.6.0\dist\main.js:15430:27)

I ignored those and reloaded/restarted VSCode instead. Afterwards there weren't any json parsing errors any more.

Finally, select the newly added kit (Command Palette: > CMake: Select a Kit). Now I have the correct environment when building.

I hope it helps.

danimihalca commented 3 years ago

Been having the same issue and output like you with msvc2015 installed from a VS 2017 setup on Windows 10, with other IDEs as well. What I've found then is that Windows 10 comes with some sort of .Net Framework which also has a MSBuild by itself which is found in path before the one from MSVC, and the only working solution was to prepend to PATH the correct MSBuild, e.g. in my case %programfiles(x86)%/Microsoft Visual Studio/2017/Proffesional/MSBuild/15.0/Bin

gcampbell-msft commented 2 days ago

@sarunint @pborsutzki @danimihalca Is this issue still remaining?

pborsutzki commented 2 days ago

@gcampbell-msft fortunately my team and I do not rely on Visual Studio 2015 toolchains any more, so I can't tell. Though we currently do not have problems using Visual Studio 2022 toolchains with the extension.

danimihalca commented 2 days ago

@sarunint @pborsutzki @danimihalca Is this issue still remaining?

I'm not using that environment anymore, therefore I cannot reproduce it, nor is it relevant for me as a consumer.