Issue
I'm trying to set up a task for compiling my C++ code in Visual Studio Code. I can't get it to work... but the command it spits out works perfectly fine when I just open the Developer Command Prompt and paste it in.
I've managed to narrow down this problem to the correct environment variables not being set in the shell that VS Code is using (as evidenced by running echo %INCLUDE%
just returning %INCLUDE%
).
Now I don't exactly know how the Developer Command Prompt differs from a normal Powershell terminal as used by VS Code, so I wouldn't know exactly how to configure it (aside from running vcvarsall.bat
), but even if I could, every time I open a new terminal in VS Code the environment variables have reset themselves again.
In essence, the solutions to this problem that I can see are:
Run
vcvarsall.bat
before every build task.Unfortunately I'm not familiar enough to know how to execute multiple commands in a row using a
tasks.json
configuration file.Configure the shell that VS Code uses to be like the Developer Command Prompt by default.
Unfortunately, I have no clue where to even start with this. I can easily set the shell used to either cmd or PowerShell, but not to the Developer Command Prompt, and neither can I find where to configure its environment variables, nor do I know what the full effects of
vcvarsall.bat
are so I know which variables to set.
If there's a simpler way of achieving what I'm after, I'd be very happy to hear it. Though regardless, what it comes down to is that I want to know how to configure VS Code in a way that allows me to compile my code from inside the IDE.
Solution
I found an answer after a bunch more poking around. My setup (in tasks.json
) is now as follows:
"command": "&",
"args": [
"'D:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Auxiliary\\Build\\vcvars32.bat';",
"cl.exe",
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
]
with &
you can execute a path that contains spaces. This leads to my vcvars32.bat
(Location may be different for other people) which sets up the correct variables without having to enter them manually. ;
lets you execute multiple commands one after the other in PowerShell.
Answered By - gamesaucer Answer Checked By - Gilberto Lyons (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.