El TecnoBaúl de Kiquenet

Kiquenet boring stories

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

Anuncios

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

 
A %d blogueros les gusta esto: