In my experience that is just the silly amount of variables you have to export to use the VC++ compiler and this is why they provide a dedicated terminal prompt for the VC++ compiler with all the right env vars loaded. I've struggled as well automating VC++ compilation in rust as a result.
If you're so inclined to revisit this using mingw with rust you can see how here https://rust-lang.github.io/rustup/installation/windows.html
This is far easier to automate imo