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?
VS Code maintains a debug session while the program is running, and pressing the Stop button terminates the program.
In order to cancel the running build, you can click on Build -> Cancel Build in the top menu.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With