The blog has moved to a new address. The blog is now located at http://devintelligence.com

Monday, July 02, 2007

Kill specific tasks from MsBuild

This is an example that presents the way - how to kill the processes in MSBUILD script.It's very useful when you need to shutdown some application or services - to prevent the script from failing because the running processes are locked .I use well known OS command "Taskkill" with two arguments /F (Specifies to forcefully terminate process) and /IM (Specifies the image name of the process that has to be terminated. Wildcard '*' can be used to specify all image names).

<Project DefaultTargets = "Kill"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >



<!-- List of processes to kill -->
<ItemGroup>
<Process Include="Process1.exe" />
<Process Include="Service1.exe" />
<Process Include="Engine1.exe" />
</ItemGroup>

<Target Name = "Kill">
<Exec Command="taskkill /F /IM %(Process.Identity)" IgnoreExitCode="true" />
</Target>
</Project>

No comments: