VSCode shows error in CMakeLists.txt despite project building just fine; how to match VSCode $ENV with PlatformIO build system's?

PlatformIO does not export IDF_PATH etc in the VSCode / system’s environment variables, it only does so during runtime when VSCode calls into pio run for compilation. The CMake extension will not work with PlatformIO in the ESP-IDF project case and show false errors.

You may be able to fix it externally by adding the IDF_PATH variable to your user’s environment variables with value C:\Users\<user>\.platformio\packages\framework-espidf, and maybe also have C:\Users\<user>\.platformio\packages\toolchain-xtensa32\bin in your path.