FalconDW

Hello -

I'm fairly new to MSBuild scripting. I have a team build that I've created in which I wrote several custom command exec's (to handle deployment) in the "AfterDropBuild" task. However, even when one of the project solutions fails to compile, it still executes the afterdropbuild task.

How can I base this task (or others) on the condition of whether or not the code compiled successfully Any help or references to articles online would be great.

I've found it somewhat frustrating to learn MSBuild mostly because I have yet to find a really good list of all the stuff I can do with it. (usually the msdn documentation is great, but for whatever reason I don't seem to be having too good of an experience with it regarding MSBuild) I've been having to learn by example through other blog / forum posts, which is great until you are trying to do something you can't find an example for. Smile

Thanks!



Re: Team Foundation Server - Build Automation How can I fail build conditionally?

Aaron Hallberg - MSFT

The simplest option would be to put your Exec tasks into a target that runs on compilation success and not on compilation failure. AfterDropBuild is not one of those targets - it is executed whether compilation succeeds or not, on the theory that whatever binaries were built should get copied to the drop location. I would recommend AfterCompile instead - if any of your solutions fail to build, this target will never be executed.

-Aaron






Re: Team Foundation Server - Build Automation How can I fail build conditionally?

FalconDW

Thanks for the help Aaron! I was happy with AfterCompile for a while, but then I realized that there were still some items I was dependending on for my deployment steps that were not completed until targets that came after "AfterCompile"... so placing my exec tasks in AfterCompile ended up not working out for me.

I know I can solve this by writing a custom task... or perhaps numerous other methods that require some coding... but I wasn't anxious to do that. Instead I ended up opting for what I consider to be a pretty hacky workaround - in the AfterCompile target I essentially use MakeDirectories to create a dummy c:\buildsucceeded dir. Then in my AfterDropBuild target header, I add a condition=exists on that c:\buildsucceeded dir. Then the first step of my AfterDropBuild I use the RemoveDirectories command on it. I could have also done this with a file instead of a directory, but the directory commands and exists conditions seemed like less work. Smile

It would be nice in the future to have the ability to create my own booleans in the build script without having to write custom tasks, or even have more accessible proprties in msbuild that I can base conditions on (e.g. 'buildsucceeded').





Re: Team Foundation Server - Build Automation How can I fail build conditionally?

Aaron Hallberg - MSFT

Sounds like you already have things under control, but you can in fact create your own properties in the build script. Try something like the following:

<Target Name="AfterCompile">
<CreateProperty Value="true">
<Output TaskParameter="value" PropertyName="BuildSucceeded" />
</CreateProperty>
</Target>

<Target Name="AfterDropBuild" Condition=" '$(BuildSucceeded)'=='true' ">
<!-- Do your stuff here. -->
</Target>

-Aaron




Re: Team Foundation Server - Build Automation How can I fail build conditionally?

FalconDW

That was exactly what I was looking for. Perfect! Thanks!