Repository: vscode
Issue: "Run VS Code outside the Developer Command Prompt" instructions fail if opened file's basename and/or dirname contains space characters
Labels: bug,tasks

This is actually a reproduction of issue #135994 which was closed due to insufficient information to consistently recreate it. Hopefully, this new report will shed more light on the problem.

**Steps to Reproduce**

1. If necessary, configure VS Code for Microsoft C++ (see _Prerequisites_ section in [this tutorial](https://code.visualstudio.com/docs/cpp/config-msvc#_prerequisites)).
2. Follow [this guide](https://code.visualstudio.com/docs/cpp/config-msvc#_run-vs-code-outside-the-developer-command-prompt) to create a `tasks.json` configuration for running VS Code outside the Developer Command Prompt for Visual Studio.
3. Create a C/C++ source file containing at least one space character in its basename or dirname.
4. Attempt to build the source file using the task created in step 2.

**Expected Result**
The integrated shell opens and the build is successfully completed, e.g. building `c:\Test\test.c` results in this terminal output:

```
*  Executing task: cl.exe /Zi /EHsc /Fe: c:\Test\test.exe c:\Test\test.c 

**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.3.0
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
Microsoft (R) C/C++ Optimizing Compiler Version 19.33.31629 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

test.c
Microsoft (R) Incremental Linker Version 14.33.31629.0    
Copyright (C) Microsoft Corporation.  All rights reserved.

/debug
/out:c:\Test\test.exe
test.obj
 *  Terminal will be reused by tasks, press any key to close it. 
 ```

**Actual Result**
The terminal process terminates with exit code 1, apparently because the double quotes enclosing the second shell argument string in `tasks.json` are being internally dropped, thus attempting to build `c:\Test\test file.c` yields:
```
 *  Executing task: cl.exe /Zi /EHsc /Fe: "c:\Test\test file.exe" "c:\Test\test file.c" 

'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/Microsoft Visual Studio/2022/Community/Common7/Tools/VsDevCmd.bat" && cl.exe /Zi /EHsc /Fe: "c:\Test\test file.exe" "c:\Test\test file.c"" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 
 ```

**Additional Info**
For reference, here is what my `tasks.json` file looks like:

```
{
	"version": "2.0.0",
	"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/Microsoft Visual Studio/2022/Community/Common7/Tools/VsDevCmd.bat\"",
			"&&"
		  ]
		}
	  }
	},
	"tasks": [
        {
            "type": "shell",
            "label": "cl.exe build active file",
            "command": "cl.exe",
            "args": [
                "/Zi",
                "/EHsc",
                "/Fe:",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "${file}"
            ],
            "problemMatcher": [
                "$msCompile"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
  }
```
**Current Workarounds**

- Remove any space characters present in the opened file's basename and/or dirname.
- If spaces must be retained, delete the escaped double quotes in line 10 of `tasks.json` and then use the caret (`^`) to escape all the space characters along with any parentheses, if present. Example:

  Before:
  ```			
            "\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools/VsDevCmd.bat\"",
  ```
  After:
  ```
            "C:/Program^ Files^ ^(x86^)/Microsoft^ Visual^ Studio/2019/Community/Common7/Tools/VsDevCmd.bat",
  ```

<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` to check. -->
Does this issue occur when all extensions are disabled?: Yes

<!-- 🪓 If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. -->
<!-- 📣 Issues caused by an extension need to be reported directly to the extension publisher. The 'Help > Report Issue' dialog can assist with this. -->
- VS Code Version: 1.70.2 (also reproducible on 1.71.0-insider)
- OS Version: Windows 10.0.19044.1889