Execute post build event in VS only when key is pressed
-
27-06-2021 - |
Question
I have a post build app that takes a long time to execute. So I need to execute it only when I really need it. Is there a way to execute such an app only when I've pressed a key (eg. SHIFT) and built the project at the same time?
Solution
That's going to be a bit difficult, build events execute in a hidden console mode app, started by msbuild.exe. Directly interacting with the user is not an option.
One thing you can do is write a little program that calls/pinvokes GetAsyncKeyState() to check if VK_SHIFT is down. And set the process exit code accordingly. Which you can then call in your post build event and use if %ERRORLEVEL% to check that return value.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow