Can I make &msbuild fail if it actually fails?

45 views
Skip to first unread message

Mikael Henriksson

unread,
Jul 23, 2010, 9:11:52 AM7/23/10
to psake...@googlegroups.com
Hi,

I have a little something that has been very irritating. Can someone tell me how to solve this?

I don't know how to make msbuild fail if it actually fails to give you an example:
[15:06:01]: Executing task: PrepareTests
[15:06:02]: Executing task: StageTest
[15:06:02]: Missing Assembly: PlaynGO.KnowYourCustomer.Specs.dll
[15:06:02]: Executing task: StageRelease
[15:06:02]: Build Succeeded!
[15:06:02]: ----------------------------------------------------------------------
[15:06:02]: Build Time Report
[15:06:02]: ----------------------------------------------------------------------
[15:06:03]: Name Duration
[15:06:03]: ---- --------
[15:06:03]: Clean 00:00:00.0774106
[15:06:03]: Init 00:00:00.8171058
[15:06:03]: Compile 00:00:16.0259708
[15:06:03]: PrepareTests 00:00:16.8269866
[15:06:03]: StageTest 00:00:17.5453679
[15:06:03]: StageRelease 00:00:17.6066058
[15:06:03]: stage 00:00:17.6087522
[15:06:03]: Total: 00:00:18.0606700
[15:06:03]: Process exited with code 0
[15:06:03]: Publishing artifacts

Thats all good and well but it's a lie. Reason:
[15:06:00]: Microsoft (R) Build Engine Version 3.5.30729.1
[15:06:00]: [Microsoft .NET Framework, Version 2.0.50727.4200]
[15:06:00]: Copyright (C) Microsoft Corporation 2007. All rights reserved.
[15:06:01]: CSC : error CS2001: Source file 'Product.cs' could not be found
[15:06:01]: CopyFilesToOutputDirectory:
 

James Kovacs

unread,
Jul 23, 2010, 10:20:12 AM7/23/10
to psake...@googlegroups.com
Are you wrapping msbuild in exec {}?

task compile -depends clean {
  exec { msbuild Foo.sln }
}

By default, PowerShell doesn't recognize non-zero exit codes from executables as an error. The exec {} function turns non-zero last exit codes into an exception so expected exception handling can occur.

HTH,
James
--
James Kovacs, B.Sc., M.Sc., MCSD, MCT
Microsoft MVP, ASP/ASP.NET
http://www.jameskovacs.com
jko...@post.harvard.edu | @jameskovacs
403-397-3177 (mobile)


--
You received this message because you are subscribed to the Google Groups "psake-users" group.
To post to this group, send email to psake...@googlegroups.com.
To unsubscribe from this group, send email to psake-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/psake-users?hl=en.

Mikael Henriksson

unread,
Jul 23, 2010, 10:46:51 AM7/23/10
to psake...@googlegroups.com
Hi James,

Thank you for the suggestion. I'll update my build scripts accordingly.
Reply all
Reply to author
Forward
0 new messages