El TecnoBaúl de Kiquenet

Kiquenet boring stories

Archive for the ‘MsBuild’ Category

Handling Custom Error Codes with MSBuild

Posted by kiquenet en 28 julio 2010

If you are running an external EXE using the "<Exec" task, then if the EXE is returning a code other than "0" as the success code, then MSBuild still takes it as as failure.

<Exec Command=’"C:\Some.exe"’>
              <Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
  </Exec>
  <Message Text="The exit code is $(ErrorCode)"/>

The execution does not even come to the "<Message" and it just exits assuming that "-1" is afailure.
As a workaround, you can use this method.

<Target Name="ExecuteSomeEXE">
<Exec Command=’"C:\Some.exe"’ ContinueOnError=’true’>
              <Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
  </Exec>
  <Message Text="The exit code is $(ErrorCode)"/>
  <Error Text="Error while executing Some EXE" Condition="’$(ErrorCode)’ > ‘0’" />
<OnError ExecuteTargets="MessageErrorHandler"/>
</Target>
<Target Name="MessageErrorHandler">
        <Message Text="An error has occurred while executing SomeEXE"/>
</Target>

This way you can manage any error code returned by the executable.

http://geekswithblogs.net/SudheersBlog/archive/2007/10/19/116171.aspx

Posted in .NET, MsBuild | Etiquetado: , , | Leave a Comment »