I am debugging a service running on a remote machine, written in C++ and built in Visual Studio 2019. By configuring the Remote Debugger in Project -> Properties -> Configuration Properties -> Debugging, I am able to deploy the build output to the remote machine and start the application with the debugger attached.
Sometimes, I need to attach to the service when it is already running, or perform some additional setup before it is started - and while in VS Code it would be a matter of adding a preLaunchTask in launch.json, I cannot find a way to automate that in Visual Studio 2019.
I tried preparing a batch script that would perform these tasks and start the service afterwards, and adding it to the Configuration Properties -> Debugging -> Remote Command field, but that causes the debugger to attach to cmd.exe instead of my program. In Configuration Properties -> Custom Build Step -> Execute After, I did not find any step related to debugging or deploying the project other than Run, which does not seem to get executed when launching the debugging session.
As a workaround, I can add a post-build event to locally run a script which will copy the generated files to the remote machine and prepare the service, and build the project every time, but this is not ideal - for one, I would have to hard-code the credentials for the remote machine within the script.
Is it possible to automatically execute a custom command - preferably on a remote machine - either after deploy, or before debugging, in a Visual Studio 2019 C++ project? Alternatively, is it possible to configure the Remote Debugger to run a script whenever a session is launched?