[Bug] current working directory is not changed when using `CMake: Run Without Debugging`
Brief Issue Summary
When binaryDir is changed by changing Configuration Preset, or by using cmake.buildDirectory in settings.json file, CMake: Run Without Debugging (from status bar or via Command Palette) doesn't change directory of Cmake/Launch terminal.
CMake Tools Diagnostics
{
"os": "win32",
"vscodeVersion": "1.103.1",
"cmtVersion": "1.21.36",
"configurations": [
{
"folder": "e:\\DEV\\C++\\Projects\\vscode-cmake-wrong-directory",
"cmakeVersion": "4.1.0",
"configured": true,
"generator": "Ninja",
"usesPresets": true,
"compilers": {
"C": "cl.exe",
"CXX": "cl.exe"
}
}
],
"cpptoolsIntegration": {
"isReady": true,
"hasCodeModel": true,
"activeBuildType": "Release",
"buildTypesSeen": [
"Release"
],
"requests": [],
"responses": [],
"partialMatches": [],
"targetCount": 1,
"executablesCount": 1,
"librariesCount": 0,
"targets": [
{
"name": "HelloWorld",
"type": "EXECUTABLE"
}
]
},
"settings": [
{
"communicationMode": "automatic",
"useCMakePresets": "always",
"configureOnOpen": true
}
]
}
Debug Log
[main] Building folder: E:/DEV/C++/Projects/vscode-cmake-wrong-directory/build/Windows-MSVC-Release HelloWorld
[main] Saving open files before configure/build
[build] Starting build
[driver] Start build HelloWorld
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build E:/DEV/C++/Projects/vscode-cmake-wrong-directory/build/Windows-MSVC-Release --config Release --target HelloWorld --
[proc] with environment: ######################## N/A ########################
[build] ninja: no work to do.
[driver] Build completed: 00:00:00.048
[cmakefileapi-parser] Read reply folder: E:\DEV\C++\Projects\vscode-cmake-wrong-directory\build\Windows-MSVC-Release\.cmake\api\v1\reply
[cmakefileapi-parser] Found index files: ["cache-v2-f7a7b30d5606e31d8cbf.json","cmakeFiles-v1-fe9c08706dd55d49eb4d.json","codemodel-v2-376011dbf1f65144925d.json","directory-.-Release-d0094a50bb2071803777.json","index-2025-08-15T18-12-38-0913.json","target-HelloWorld-Release-ddab750cf9c9297d5e78.json","toolchains-v1-b72720c52195983157ee.json"]
[build] Build finished with exit code 0
[cache] Reading CMake cache file E:/DEV/C++/Projects/vscode-cmake-wrong-directory/build/Windows-MSVC-Release/CMakeCache.txt
[cache] Parsing CMake cache string
[extension] [7295] cmake.launchTarget finished (returned {"name":"CMake/Launch - HelloWorld","processId":{},"creationOptions":{"name":"CMake/Launch - HelloWorld","env":{"########################": "N/A ########################","CC":"cl.exe","CXX":"cl.exe","_CMAKE_TOOLS_LAUNCH_TERMINAL_TARGET_NAME":"HelloWorld","_CMAKE_TOOLS_LAUNCH_TERMINAL_PATH":"C:\\WINDOWS\\System32\\cmd.exe"},"cwd":"E:\\DEV\\C++\\Projects\\vscode-cmake-wrong-directory\\build\\Windows-MSVC-Debug"},"state":{"isInteractedWith":true,"shell":"cmd"},"dimensions":{"columns":175,"rows":20}})
[extension] [7730] cmake.logDiagnostics started
[extension] [7730] cmake.logDiagnostics finished (returned undefined)
Additional Information
Using a simple c++ program to print current path:
Steps to reproduce:
- vscode-cmake-wrong-directory.zip
- set preset to "GCC-Debug" run with status bar or via
CMake: Run Without Debugging - set preset to "GCC-Release" run with status bar or via
CMake: Run Without Debugging - set preset to "Clang-Debug" run with status bar or via
CMake: Run Without Debugging - set preset to "Clang-Release" run with status bar or via
CMake: Run Without Debugging - see that all are run inside
GCC-Debugdirectory
Also, I noticed that changing compiler to or from MSVC resets CMake/launch terminal (probably to set up environment) and because of this reset changing compiler to or from MSVC doesn't cause this issue. (changing configuration while in MSVC still causes this issue though)
Changing compiler between GCC and Clang causes this issue because terminal is not reset.
@Count-MHM Thank you for your report. We tried to check this issue in the sample project. It seems that we reproduced this issue, but the results are slightly different from yours. Could you recheck this issue? if we missed anything, please let us know. Thank you.
@yanghhhhhhh Yes, that was what I'm experiencing. I'm not sure what you mean by differences, if you mean that gcc and clang runs are not being shown in the same terminal, it is because the GIF closes the terminal before running clang. If there is another difference that I missed please let me know.
This is my reproduction with an empty VSCode profile with only ms-vscode.cpptools-extension-pack installed
https://github.com/user-attachments/assets/a62dd38d-acff-46f5-91eb-9d057d001e96
@Count-MHM Hi , thanks for reporting issue here! Reproduced this issue on CMake Tools v1.21.36 release version. Repro Steps:
- Download the attached project and open it. (vscode-cmake-wrong-directory.zip)
- Open CMake pane, choose "GCC-Debug", press F1 and run command: "CMake: Run Without Debugging".
- Choose "GCC-Release", press F1 and run command: "CMake: Run Without Debugging".
- Choose "Clang-Debug", press F1 and run command: "CMake: Run Without Debugging".
- Choose "Clang-Release", press F1 and run command: "CMake: Run Without Debugging".
- Choose "MSVC-Debug", press F1 and run command: "CMake: Run Without Debugging".
- Choose "MSVC-Release", press F1 and run command: "CMake: Run Without Debugging".
- Observe the debug output, they all run inside GCC-Debug directory.
Details please see following video:
FYI: @gcampbell-msft