Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 391
Narek Malkhasyan Avatar asked Sep 30 '11 15:09

Narek Malkhasyan


People also ask

How do I stop a running process in Visual Studio code?

VS Code maintains a debug session while the program is running, and pressing the Stop button terminates the program.

How do I stop the current publish operation in Visual Studio?

In order to cancel the running build, you can click on Build -> Cancel Build in the top menu.


1 Answers

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.

like image 71
tpower Avatar answered Sep 25 '22 00:09

tpower