I have seen a ton of crazy workarounds for handling this seemingly simple task. It turns out that most people change the project targets and other nitty gritty manual edit file changes. It turns out the way I am doing it is much easier.
Visual Studio gets really annoyed when a tool returns anything but zero,and it has good reason. The compiler directives tell it to do that in your project file. So, what the remedy, make every tool return zero…Impossible you say! Nope. Easy.
So, it’s so easy it will probably annoy you. Take your scripts and put all the calls into a batch file. Make the last line of the batch file EXIT 0
Yup Exit 0 <– thats a zero.
Here is the one I use to disable my service when I build, so I don’t get the annoying file in use error.
net stop "Your service name here" EXIT 0