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

"Run VS Code outside the Developer Command Prompt" instructions in documentation do not work #135994

Closed
cncz42 opened this issue Oct 27, 2021 · 11 comments
Assignees
Labels
*not-reproducible Issue cannot be reproduced by VS Code Team member as described

Comments

@cncz42
Copy link

cncz42 commented Oct 27, 2021

Does this issue occur when all extensions are disabled?: Yes/No
Yes

  • VS Code Version: 1.61.2
  • OS Version: Windows 11 Pro 22000.258

Steps to Reproduce:

  1. Create c++ code and install msvc as specified in this documentation
  2. Amend tasks.json according to this section
  3. Hit ctrl+shift+b
  4. Code doesn't compile, showing the error:
    'C:/Program' is not recognized as an internal or external command, operable program or batch file. The terminal process "cmd.exe /C "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools/VsDevCmd.bat" && cl.exe /Zi /EHsc /Fe: "c:\Users\cncz4\OneDrive\Code Projects\CppTest\test.exe" "c:\Users\cncz4\OneDrive\Code Projects\CppTest\test.cpp"" terminated with exit code: 1.
    It does compile correctly when run out of a developer command prompt and the bat is in the right path, so either there's an obscure configuration error on my end or that documented tasks.json edit is wrong/out of date.
@cncz42 cncz42 changed the title "Run VS Code outside the Developer Command Prompt" method in documentation does not work "Run VS Code outside the Developer Command Prompt" instructions in documentation do not work Oct 27, 2021
@cncz42
Copy link
Author

cncz42 commented Oct 28, 2021

Neglected to mention this can be fixed by replacing line 10 of the example with:
"C:\\Program^ Files^ ^(x86^)\\Microsoft^ Visual^ Studio\\2019\\Community\\Common7\\Tools\\VsDevCmd.bat",
There's probably a better looking fix though

@alexr00 alexr00 self-assigned this Oct 28, 2021
@alexr00
Copy link
Member

alexr00 commented Oct 28, 2021

I'm not able to reproduce this issue. Did you copy the entire tasks.json from step 2?

@alexr00 alexr00 added the info-needed Issue requires more information from poster label Oct 28, 2021
@cncz42
Copy link
Author

cncz42 commented Oct 29, 2021

Apologies for the late reply, the tasks.json is copied in it's entirety, I even tested the same scenario on a 2nd computer with the same spacing issue appearing.

@alexr00
Copy link
Member

alexr00 commented Oct 29, 2021

Can you share all your VS Code settings?

@cncz42
Copy link
Author

cncz42 commented Oct 29, 2021

Settings are pretty basic but sure:
https://gist.github.com/cncz42/218f7219feec35ed25eb392a1bc6fce6

@sdsong616
Copy link

sdsong616 commented Nov 27, 2021

I met the same issue too.
OS: Windows 10 Professional Edition (Simplified Chinese) 19044.1387
Vs Code version: 1.62.3
Repro steps are same as @cncz42 's, but "C:\Program^ Files^ ^(x86^)\Microsoft^ Visual^ Studio\2019\Community\Common7\Tools\VsDevCmd.bat" doesn't work for me.

@alexr00
Copy link
Member

alexr00 commented Feb 15, 2022

I still can't reproduce this when I copy verbatim from https://code.visualstudio.com/docs/cpp/config-msvc#_run-vs-code-outside-the-developer-command-prompt.

If you make a mistake while copying then you could see the described error. Note that the line in question has \" in it:

[
    "\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools/VsDevCmd.bat\"", // this is correct
    "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools/VsDevCmd.bat" // this is incorrect
]

@alexr00 alexr00 closed this as completed Feb 15, 2022
@alexr00 alexr00 added *not-reproducible Issue cannot be reproduced by VS Code Team member as described and removed info-needed Issue requires more information from poster labels Feb 15, 2022
@drakmaniso
Copy link

I have the same issue ("'C:/Program' is not recognized as an internal or external command"). The path I use does contain \":

	"windows": {
		"options": {
			"shell": {
				"executable": "cmd.exe",
				"args": [
					"/C",
					// The path to VsDevCmd.bat depends on the version of Visual Studio you have installed.
					"\"C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/Tools/VsDevCmd.bat\"",
					"&&"
				]
			}
		}
	},

The workaround proposed by @cncz42 doesn't work for me. Typing cmd /C "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/Tools/VsDevCmd.bat" directly in a terminal works correctly.

@Guyutongxue
Copy link

Guyutongxue commented Mar 9, 2022

I ran into this problem too. But eventually found out that I had misspelled the path. If the text in quotes passed into cmd /C is not an executable file or script, then the pair of quotes will not be preserved.


EDIT: Also notice that, the command field of the build task must be a single cl.exe without absolute path.

@drakmaniso
Copy link

Unfortunately, in my case, the path is correct, and corresponds to the actual script. The exact same path works if copy-pasted into a terminal.
The other parts of the build task are probably correct too, since the task works if vscode is started from a developper command prompt.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*not-reproducible Issue cannot be reproduced by VS Code Team member as described
Projects
None yet
Development

No branches or pull requests

6 participants
@sdsong616 @drakmaniso @Guyutongxue @alexr00 @cncz42 and others