Geeks With Blogs
Sudheer Kumar ASP.Net, C#, BizTalk, MSBuild, WPF, WCF, WF....
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. Posted on Friday, October 19, 2007 3:40 PM MSBuild | Back to top


Comments on this post: Handling Custom Error Codes with MSBuild

# if one target executes then run another target,...how to write the script please tell me
Requesting Gravatar...
if u knw lwt mew knoe
Left by dev on Feb 09, 2009 11:26 AM

# re: Handling Custom Error Codes with MSBuild
Requesting Gravatar...
Very useful information! Thanks!
Left by payroll solutions on Feb 28, 2011 2:20 AM

# re: Handling Custom Error Codes with MSBuild
Requesting Gravatar...
Thanks for your post.
Left by ice maker on Apr 01, 2011 3:10 AM

Your comment:
 (will show your gravatar)


Copyright © Sudheer Kumar | Powered by: GeeksWithBlogs.net