Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVC IntelliSense mode configuration should use MSVC Environment variables (CL, _CL_, INCLUDE, LIBPATH) #9745

Closed
urisimchoni opened this issue Aug 16, 2022 · 6 comments
Assignees
Labels
bug Feature: Configuration An issue related to configuring the extension or IntelliSense fixed Check the Milestone for the release in which the fix is or will be available. Language Service
Milestone

Comments

@urisimchoni
Copy link

Brief Issue Summary

I've created a small VSCode project that builds a native DLL on Windows, using CMake and Ninja (basically took the template created by Visual Studio). The project includes files from the .Net SDK.

Somehow, the CMake Tools extension is able to configure and build this project just fine (without me having to tell it where the Visual Studio tools and the .Net SDK is), but when configuring the c_cpp extension (for intellisense and such), the configuration seems incomplete and does not include the .Net SDK header directories, which forces me to avoid this auto-configuration and manually specify the directory.

I'm tried running vscode from a "vcvars" command prompt as suggested by documentation, it seems to make no difference.

When starting a vcvars64.bat session and configuring/building the project from command line, it looks like the CL.exe command line doesn't include the .Net SDK path either, so I guess CL is finding the header files from the INCLUDE environment variable that is set by vcvars64.bat - This might suggest that this is really a CMake issue (shouldn't CMake create a makefile that has all information needed to build, without relying on env vars?), but I figured I'd start with this project and see where it goes. In any case, I really don't understand why some Visual C++ /SDK directories are passed to c_cpp extension and some don't.

Thanks,
Uri.

CMake Tools Diagnostics

{
  "os": "win32",
  "vscodeVersion": "1.70.1",
  "cmtVersion": "1.11.26",
  "configurations": [
    {
      "folder": "c:\\dev\\vfagent.net",
      "cmakeVersion": "3.24.0",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": true,
      "compilers": {
        "C": "cl.exe",
        "CXX": "cl.exe"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug"
    ],
    "requests": [
      "file:///c%3A/dev/vfagent.net/agent/CorProfiler.cpp"
    ],
    "responses": [
      {
        "uri": "file:///c%3A/dev/vfagent.net/agent/CorProfiler.cpp",
        "configuration": {
          "includePath": [],
          "defines": [
            "_CRT_SECURE_NO_WARNINGS",
            "vfagent_net_EXPORTS"
          ],
          "compilerPath": "c:/program files/microsoft visual studio/2022/professional/vc/tools/msvc/14.32.31326/bin/hostx64/x64/cl.exe",
          "compilerArgs": [],
          "compilerFragments": [
            "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1",
            "-std:c++20"
          ]
        }
      }
    ],
    "partialMatches": [],
    "targetCount": 1,
    "executablesCount": 0,
    "librariesCount": 1,
    "targets": [
      {
        "name": "vfagent.net",
        "type": "MODULE_LIBRARY"
      }
    ]
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": null
    }
  ]
}

Debug Log

[main] Configuring folder: vfagent.net 
[main] Saving open files before configure/build
[driver] Start configure 
[driver] Running pre-configure checks and steps
[cmakefileapi-driver] Configuring using preset
[cmakefileapi-driver] Invoking CMake C:\Program Files\CMake\bin\cmake.exe with arguments ["-DCMAKE_BUILD_TYPE=Debug","-DCMAKE_C_COMPILER=cl.exe","-DCMAKE_CXX_COMPILER=cl.exe","-DCMAKE_INSTALL_PREFIX=c:/dev/vfagent.net/out/install/x64-debug","-Sc:/dev/vfagent.net","-Bc:/dev/vfagent.net/out/build/x64-debug","-G","Ninja"]
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe -DCMAKE_INSTALL_PREFIX=c:/dev/vfagent.net/out/install/x64-debug -Sc:/dev/vfagent.net -Bc:/dev/vfagent.net/out/build/x64-debug -G Ninja
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: C:/dev/vfagent.net/out/build/x64-debug
[cmakefileapi-parser] Read reply folder: c:\dev\vfagent.net\out\build\x64-debug\.cmake\api\v1\reply
[cmakefileapi-parser] Found index files: ["cache-v2-c80b91d77329b64b39ee.json","codemodel-v2-cd7be87d0caed3bd7f3b.json","directory-.-Debug-d0094a50bb2071803777.json","directory-agent-Debug-31b27c945164c224322b.json","index-2022-08-16T08-16-12-0836.json","target-vfagent.net-Debug-732220c1884abc22fd70.json","toolchains-v1-8430c873a609711a98fe.json"]
[cache] Reading CMake cache file c:/dev/vfagent.net/out/build/x64-debug/CMakeCache.txt
[cache] Parsing CMake cache string
[extension] [9450] cmake.configure finished (returned 0)
[extension] [5378] cmake.logDiagnostics started
[extension] [5378] cmake.logDiagnostics finished (returned undefined)

Additional Information

Debug log of the c_cpp extension upon running CMake: Configure:

cpptools/fileCreated: C:\dev\vfagent.net\out\build\x64-debug.cmake\api\v1\reply\index-2022-08-16T11-14-59-0730.json
Checking for syntax errors: C:\dev\vfagent.net\agent\CorProfiler.h
Queueing IntelliSense update for files in translation unit of: C:\dev\vfagent.net\agent\CorProfiler.cpp
cpptools/fileDeleted: C:\dev\vfagent.net\out\build\x64-debug.cmake\api\v1\tmp.json
cpptools/fileDeleted: C:\dev\vfagent.net\out\build\x64-debug.cmake\api\v1\reply\index-2022-08-16T08-16-12-0836.json
Custom browse configuration received: {
"browsePath": [
"c:/dev/vfagent.net/agent/asmhelpers/amd64/windows",
"c:/dev/vfagent.net/agent"
],
"compilerPath": "c:/program files/microsoft visual studio/2022/professional/vc/tools/msvc/14.32.31326/bin/hostx64/x64/cl.exe",
"compilerArgs": [],
"compilerFragments": [
"/DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1",
"-std:c++20"
]
}
cpptools/clearCustomConfigurations
Checking for syntax errors: C:\dev\vfagent.net\agent\CorProfiler.h
Shutting down IntelliSense server: C:\dev\vfagent.net\agent\CorProfiler.cpp
cpptools/queryTranslationUnitSource: C:\dev\vfagent.net\agent\CComPtr.h (id: 49)
Custom configurations received:
uri: file:///c%3A/dev/vfagent.net/agent/CorProfiler.cpp
config: {
"includePath": [],
"defines": [
"_CRT_SECURE_NO_WARNINGS",
"vfagent_net_EXPORTS"
],
"compilerPath": "c:/program files/microsoft visual studio/2022/professional/vc/tools/msvc/14.32.31326/bin/hostx64/x64/cl.exe",
"compilerArgs": [],
"compilerFragments": [
"/DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1",
"-std:c++20"
]
}
cpptools/didChangeCustomBrowseConfiguration
Attempting to get defaults from C++ compiler in "compilerPath" property: 'c:/program files/microsoft visual studio/2022/professional/vc/tools/msvc/14.32.31326/bin/hostx64/x64/cl.exe'
cpptools/didChangeCustomConfiguration
Attempting to get defaults from C++ compiler in "compilerPath" property: 'c:/program files/microsoft visual studio/2022/professional/vc/tools/msvc/14.32.31326/bin/hostx64/x64/cl.exe'
cpptools/queryTranslationUnitSource: C:\dev\vfagent.net\agent\CorProfiler.h (id: 50)
cpptools/resumeParsing
sending compilation args for C:\dev\vfagent.net\agent\CorProfiler.cpp
include: C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\PROFESSIONAL\VC\TOOLS\MSVC\14.32.31326\INCLUDE
include: C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\PROFESSIONAL\VC\TOOLS\MSVC\14.32.31326\ATLMFC\INCLUDE
include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\UM
include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\UCRT
include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\SHARED
include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\WINRT
include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\CPPWINRT
define: _DEBUG
define: _MT
define: _DLL
other: --rtti
stdver: ms_c++20
intelliSenseMode: windows-msvc-x64
Shutting down IntelliSense server: C:\dev\vfagent.net\agent\CorProfiler.cpp
sending compilation args for C:\dev\vfagent.net\agent\CorProfiler.cpp
include: C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\PROFESSIONAL\VC\TOOLS\MSVC\14.32.31326\INCLUDE
include: C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\PROFESSIONAL\VC\TOOLS\MSVC\14.32.31326\ATLMFC\INCLUDE
include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\UM
include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\UCRT
include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\SHARED
include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\WINRT
include: C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\CPPWINRT
define: _DEBUG
define: _MT
define: _DLL
define: _CRT_SECURE_NO_WARNINGS
define: vfagent_net_EXPORTS
define: WIN32
define: _WINDOWS
other: --rtti
stdver: ms_c++20
intelliSenseMode: windows-msvc-x64
Checking for syntax errors: C:\dev\vfagent.net\agent\CorProfiler.h
Queueing IntelliSense update for files in translation unit of: C:\dev\vfagent.net\agent\CorProfiler.cpp
cpptools/finishUpdateSquiggles
Error squiggle count: 191
Error squiggles will be disabled in: file:///C%3A/dev/vfagent.net/agent/CorProfiler.h
Update IntelliSense time (sec): 1.32
cpptools/getSemanticTokens: C:\dev\vfagent.net\agent\CorProfiler.h (id: 51)

INCLUDE environment variable from "vcvars64.bat":

INCLUDE=C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.32.31326\ATLMFC\include;C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.32.31326\include;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt
LIB=C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.32.31326\ATLMFC\lib\x64;C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.32.31326\lib\x64;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\um\x64

@bobbrow
Copy link
Member

bobbrow commented Aug 16, 2022

Is this a C++/CLI project? Can you share a small sample? We can take a look and see if CMake is providing us the correct info in the cmake-file-api or not.

@bobbrow bobbrow added the more info needed The issue report is not actionable in its current state label Aug 16, 2022
@urisimchoni
Copy link
Author

Here's a basic reproducer:

  • Start with a clean Windows machine and install:
choco install git
choco install visualstudio2022professional
choco install vscode

  • Run Visual Studio installer and check "Desktop Development with C++" and ".Net Desktop Development" and install
  • Run the "Developer Command Prompt for VS 2022"
  • Create an empty directory and run vscode from it:
mkdir hello.net
cd hello.net
code .
  • Install C/C++ Extension Pack
  • Create a "Hello World" program which includes .Net SDK stuff:
#include <stdio.h>
#include "cor.h"

int main(int argc, char *argv[])
{
    printf("Hello, World!\n");
    return 0;
}
  • Create a CMakeLists.txt File
cmake_minimum_required(VERSION 3.0.0)
project(hello VERSION 0.1.0)

add_executable(hello main.cpp)
  • Configure and build (select the amd64 kit) - build is successful
  • Yet, the "cor.h" include has squiggles

(This reproducer uses msbuild because it's more minimal that way - the issue seems to occur on both msbuild and Ninja)

@urisimchoni urisimchoni changed the title VC++/Ninja - configuration passed over to c_cpp extension is incomplete VC++/.Net SDK - configuration passed over to c_cpp extension is incomplete Aug 16, 2022
@bobbrow
Copy link
Member

bobbrow commented Aug 17, 2022

Thank you! It appears that cpptools needs to add the value of %NETFXSDKDir% to the list of system include paths. I see it there in the %INCLUDE% variable in the Developer Command Prompt.

@Colengms

@bobbrow bobbrow added bug Feature: configure and removed more info needed The issue report is not actionable in its current state labels Aug 17, 2022
@Colengms
Copy link
Collaborator

Based on the info here: https://docs.microsoft.com/en-us/cpp/build/reference/cl-environment-variables?view=msvc-170

It looks like cpptools needs to consider the values of the following environment variables when configuring IntelliSense for cl.exe.

CL
_CL_
INCLUDE
LIBPATH

@Colengms Colengms transferred this issue from microsoft/vscode-cmake-tools Aug 17, 2022
@Colengms Colengms added Language Service Feature: Configuration An issue related to configuring the extension or IntelliSense and removed Feature: configure labels Aug 17, 2022
@Colengms Colengms self-assigned this Aug 17, 2022
@Colengms Colengms added this to the On Deck milestone Aug 17, 2022
@Colengms Colengms changed the title VC++/.Net SDK - configuration passed over to c_cpp extension is incomplete MSVC IntelliSense mode configuration should use MSVC Environment variables (CL, _CL_, INCLUDE, LIBPATH) Aug 17, 2022
@bobbrow
Copy link
Member

bobbrow commented Aug 17, 2022

Yes, however not everyone launches VS Code from a Developer Command Prompt. In the event that %INCLUDE% is not available, we'll need to add logic to search for the probable location of %NETFXSDKDir% (which also won't be available) and add that to the system include path.

@sean-mcmanus sean-mcmanus modified the milestones: On Deck, 1.13.4 Oct 31, 2022
@sean-mcmanus
Copy link
Collaborator

Fixed with 1.13.4 (pre-release): https://github.com/microsoft/vscode-cpptools/releases/tag/v1.13.4

@github-actions github-actions bot locked and limited conversation to collaborators Jan 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Feature: Configuration An issue related to configuring the extension or IntelliSense fixed Check the Milestone for the release in which the fix is or will be available. Language Service
Projects
None yet
Development

No branches or pull requests

5 participants