How to make Visual Studio close running process before performing build?
In addition to Morten's answer:
Use taskkill and then ignore errors.
taskkill /F /IM "$(TargetFileName)"
exit 0
An idea: Make a pre-build step for the executable project that uses Taskkill to kill the process. Read more about Taskkill here: http://technet.microsoft.com/en-us/library/bb491009.aspx
Add the following to the projects Pre-build event (based on the accepted answer):
taskkill /f /fi "imagename eq $(TargetFileName)"
The command as used in the other answer may result in an error in cases where the process is not running.
This variation uses a filter (/fi
) which does not 'fail' even if there is 0 matches.