Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Treat MSBuild exec task timeout as an error

Tags:

msbuild

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?

like image 460
Ergwun Avatar asked Dec 17 '25 15:12

Ergwun


1 Answers

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>
like image 169
KMoraz Avatar answered Dec 19 '25 06:12

KMoraz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!