Ergwun
Ergwun

Reputation: 12978

Treat MSBuild exec task timeout as an error

I'm specifying a timeout for an MSBuild Exec task like this:

<Exec Command="MyCommand.bat" Timeout="3000" />

If my command times out, MSBuild issues a warning. I would like it to instead issue an error that fails the build. How can I achieve that?

Upvotes: 3

Views: 2249

Answers (1)

KMoraz
KMoraz

Reputation: 14164

Use the OnError element and the Error Task:

<Target Name="ExecCommand">
        <Exec Command="MyCommand.bat" Timeout="3000" />
    <OnError ExecuteTargets="TimeoutErrorHandler"/>
</Target>

<Target Name="TimeoutErrorHandler">
    <Error Text="Command timeout"/>
</Target>

Upvotes: 5

Related Questions