How to make Visual Studio close running process before performing build?
I'm building WinForms 开发者_高级运维application using Visual Studio 2010. Every time I make a change in the code I have to run the application and check how it works. The problem is that I do this frequently and once I forget to close the previous instance of the application the compiler generates error "The process cannot access the file bin\Debug....". Is it possible to make Visual Studio close the running instance before performing build?
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.
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
Following code from another stackexchange answer worked for me.
wmic process where name='chromedriver.exe' delete
精彩评论