PreLaunch task for VS2019 CMake Linux projects

  • Thread starter Thread starter gzorlee
  • Start date Start date
G

gzorlee

Guest
Hello MSDN Community,

We recently started to move one of our big CMake Linux projects to remote compilation using VS2019. It is an awesome feature for sure.

However we are facing an issue I have already raised on this page (Deploy, run, and debug your C++ Linux project in Visual Studio).

Our project is enormous and requires a lot of environment variables to be set before being launched as well as argument values to be computed before being passed to our program at startup (for instance ./myProgram arg1 arg2 arg3 where some of argX needs to be computed on the spot at launch time). Both the env variables and the arguments can only be computed on Linux side.

We were thinking there would be a kind of PreLaunch tasks which are available in VS Code if I am not wrong (Could not find the preLaunch task 'build'). Could they be used to run a script which sets the env variables and then would VS run gdb and our program in the same session where the env variables are still available? We could them have the env variables set properly and the arguments could just be computed and stored in env variables too. But we were not able to find those PreLaunch tasks in VS2019. Are they available or is there and way to achieve what we want to do?

We ended up doing something hacky which was to change the pipeProgram in the launch.vs.json to run a script which in turns execute the script which set all the env variables and then launch gdb with the arguments it expects from VS (--tty and --interpreter). For instance:

{
"version": "0.2.1",
"defaults": {},
"configurations": [
{
"cwd": "${debugInfo.defaultWorkingDirectory}",
"externalConsole": true,
"MIMode": "gdb",
"name": "OMS",
"pipeTransport": {
"debuggerPath": "${debugInfo.defaultWorkingDirectory}/../../scripts/myProgram arg1 arg2 arg3 -g -y --tty=${debugInfo.tty} -i ${debuggerCommand}",
"pipeArgs": [
"/s",
"${debugInfo.remoteMachineId}",
"/p",
"${debugInfo.parentProcessId}",
"/c"
],
"pipeProgram": "${debugInfo.shellexecPath}"
},.......}


It is hacky and I am sure having a better support of this feature would help other big Linux projects to be migrated to VS which is a wonderful platform. If it is already supported then maybe have the how-to properly documented in some pages like the one mentioned above.

Thank you in advance.

Kind regards,

Guillaume.

Continue reading...
 
Back
Top