The compiler and linker "know" to stop when you cancel the assembly because they are executed as MSBuild "Task Task" and are sensitive to the ToolCanceled event.
Although you cannot do the same with a custom build step, you can wrap your tool in a class that extends ToolTask and kills your tool when ToolCanceled .
msbuild. <Code Type="class" ...
ToolTask ICancelableTask, Cancel() , .
Cancel() MSBuild, .
, Cancel():
<UsingTask TaskName="MyTool" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
</ParameterGroup>
<Task>
<Code Type="Class" Language="cs">
<![CDATA[
using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;
using System;
public class MyTool : Task, ICancelableTask
{
public override bool Execute()
{
Log.LogMessage(MessageImportance.High, "MyTool: Build started!");
// Code to run your tool...
}
public void Cancel()
{
Log.LogMessage(MessageImportance.High, "MyTool: Build cancelled!");
// Code to stop your tool...
}
}
]]>
</Code>
</Task>
</UsingTask>