Not all environment variables expanding on Windows

I’m facing this rather weird issue where some specific environment variables (when used in build_flags) are either not expanding, or not “registered” as variables at all. But, only on Windows. On a linux installation of the same PIO Core version (6.1.13), it expands fine.

Using -I ${PROJECT_DIR}/.pio/libdeps/${PIOENV}/Result/include in build_flags, expands to: -I C:\git\projectName/.pio/libdeps/${PIOENV}/Result/include. As you can see, /${PIOENV} is included in the output as if it were a normal string.
Changing the first variable to something different, such as ${PROJECT_LIBDEPS_DIR}, has the same effect as /${PIOENV}. It then expands to: -I ${PROJECT_LIBDEPS_DIR}/.pio/libdeps/${PIOENV}/Result/include.

The project in question is using the platform-espressif32, so I’m not quite sure whether this issue is caused by PIO Core, or by platform-espressif32.

What is causing this?