Thursday, March 24, 2011

MSBuild ContinueOnError

Hi

I have an MSBuild project as follows:

<Target Name="StopApplications">
 <BizTalk.BuildGenerator.Tasks.StopApplication MessageBoxConnection="$(BizTalkManagementDatabaseConnectionString)" ApplicationName="x.Direct.Brackmills"/>
 <BizTalk.BuildGenerator.Tasks.StopApplication MessageBoxConnection="$(BizTalkManagementDatabaseConnectionString)" ApplicationName="x.Direct.Manhattan"/>
</Target>

<Target Name="RemoveApplications">
 <Exec Command="BTSTask RemoveApp -ApplicationName:x.Direct.Brackmills -Server:$(BizTalkDatabaseServerName) -Database:$(BizTalkManagementDatabaseName)" />
 <Exec Command="BTSTask RemoveApp -ApplicationName:x.Direct.Manhattan -Server:$(BizTalkDatabaseServerName) -Database:$(BizTalkManagementDatabaseName)" />
</Target>

My problem is that when calling the "RemoveApplications" target, the ContinueOnError does not work as I'd expect. I have a long list of applications to stop and remove. They won't all allways be present so I need the script to continue when it finds they're not there. This seems to work find for the "StopApplications" target but when it hits a missing application in the "RemoveApplications" target I get the message:

"Done building target "RemoveApplications" in project "cleardownApplications.proj" -- FAILED. Build continuing because "ContinueOnError" on the task "CallTarget" is set to "true".

But then, it drops out of "RemoveApplications" and moved onto "AddApplications"

Any help gratefully received,

Thanks

Rob.

From stackoverflow
  • I've solved this a bit differently and uses a separate target to check if the application exists before removing it.

    <Target Name="ApplicationExists">
        <BizTalk2006.Application.Exists Application="$(ApplicationName)">
         <Output TaskParameter="DoesExist" PropertyName="ApplicationExists" />
        </BizTalk2006.Application.Exists>
    </Target>
    

    The I use that exists-target as an "condition" in other targets.

    <Target Name="DeleteApplication" Condition="$(ApplicationExists)=='True'" DependsOnTargets="ApplicationExists">
        <BizTalk2006.Application.Stop Application="$(ApplicationName)"/>
        <BizTalk2006.Application.Delete Application="$(ApplicationName)"/>
    </Target>
    
    Rob Bowman : Hi Riri, is the BizTalk2006 assembly a collection of bespoke MSBuild tasks that you've created?
    Riri : Good Q. Missed that. It's a task you'll find in the SDC library. http://www.codeplex.com/sdctasks

0 comments:

Post a Comment