Geeks With Blogs

News View Michael Stephenson's profile on BizTalk Blog Doc View Michael Stephenson's profile on LinkedIn
Michael Stephenson keeping your feet on premise while your heads in the cloud
This article is intended to explain how to use MsBuild to help you when using BAM on a BizTalk project.
When you use BAM one of the positives is that you have BM.exe and BTTDeploy.exe which can be used to help you do this deployment etc. However as I have mentioned in previous posts I feel one of the things that is a barrier to helping people get up and running with BAM is that there isn’t really anything (that I’ve seen anyway) which helps you to explain how your BAM work would fit into your normal solution development build and continuous integration processes.
To try to address this barrier hopefully this article will provide some information to help developers get over this.
I have extended the tasks within my BizTalk MsBuild Generator project on codeplex( to have some additional tasks for BAM. These tasks are nothing special and simply provide a nicer interface to BM.exe and BTTDeploy.exe.  The tasks will be published in the next release, but you can use them now by getting the sample below or contacting me.
The tasks I have created are:
Task Name
This will backup all definitions in BAM. I find this is useful so incase you happen to do something wrong you can clean the whole of your development BAM and redeploy it as it was from this backup file
This will back up the definition file in case you have a problem and need to restore it to before the most recent build
This will back up the tracking profile file in case you need to restore it to the last version
This will backup all definitions in BAM and then remove everything from BAM
This will remove a tracking profile from BAM
This will remove a definition from BAM. It will remove all activities and views defined in the .xsl or .xml file
This will remove an activity with a specific name from BAM
< BizTalk.BuildGenerator.Tasks.BAM.RemoveActivity
This will remove a tracking profile from BAM
This will remove a view with a specific name from BAM
This will deploy a definition .xsl or .xml file to BAM
This will deploy a tracking profile .btt file to BAM
This will update a definition be using the update command and supplying the updated .xsl or .xml file
Before I get into the details of the sample, some of the factors I have considered when demonstrating the process in the sample are:
·         You may have more than 1 application running/building which would need to use BAM so in most build processes you would probably not use the CleanBam task as this may break another build
·         I tend to use the backup tasks to help me because in the past I have had a few problems where I have changed for example my definition file and then couldn’t remove the definitions because the .xsl file had changed too much. 
o   To get around this I use the backup everything before I start interacting with BAM so I can get back to the previous state if it goes wrong. 
o   At the end of the build I back up the definition and tracking profile files so that if I do change them before the next build I can still remove what is there. 
o   When I remove from BAM I usually specify the paths to the backup files
o   In addition to the above you could also use the RemoveView/RemoveActivity tasks but I find this is a little more tedious as I have to remember to modify the build when I change the definition
The Sample
In the sample (available below) I have created a basic BizTalk project which just moves a file from one location to another through an orchestration. I have also created a BAM definition for it and also a tracking profile. You should be able to see these within the solution.
For the sample I don’t really want to focus on the details of the BAM definition or tracking profile, but rather the deployment and build scripts. In the build process for this application I have used the BizTalk MsBuild Generator to create the MsBuild scripts for me.
In the Acme.BizTalk.BamDemo.Custom.targets file I have extended the build process in the normal way with these scripts to add my BAM functionality. The rest of this section will discuss how I have done this.
Note: To get the build running on your machine you may have to change the following:

1.       There is a property defined in the file to indicate the location where you place the source code
2.       The bindings file may need changed to point to the correct location where you put the input and output folders.
Cleaning up BAM
In the build script I may have to deal with previous builds and deployments which have already setup and configured BAM to know about my implementation. In order to run a consistent build process it is important to clean up after any previous build. To do this in the BeforeCleanUp target I will call some of the BAM tasks to clean up BAM. The below code snippet shows that I am backing up BAM as described above, and then removing my Tracking Profile followed by my Definition.
<Target Name="BeforeCleanUp">                         
Deploying to BAM
In the build script I also want to deploy to BAM to setup the details of my tracking requirements. To do this I have chosen to extend the AfterApplyBindings target. You can do this in a few places in the build script so long as you ensure you have deployed your assemblies to the GAC and management database so they can be resolved when applying your tracking profile. You can see in the snippet below that I am using the two deployment tasks and also the two backup tasks to ensure I always have a copy of what was deployed in case I make changes that I have problems then removing or undoing.
<Target Name="AfterApplyBindings">
Hopefully this article shows that BAM is not as difficult to get up and running as you might think and this will encourage some development and project teams to use it more in their projects.  The sample is available below:
Posted on Sunday, June 15, 2008 6:10 PM BizTalk | Back to top

Comments on this post: BAM and MsBuild

# re: BAM and MsBuild
Requesting Gravatar...
I have deployed BAM in the production.
Now I need to move the newer version of orchestration to the production.
How to make sure I dont lose the earlier BAM details.

Left by Hari on Jan 13, 2009 9:39 AM

Your comment:
 (will show your gravatar)

Copyright © Michael Stephenson | Powered by: