biztalk community

Join Our Mailing List
E-mail Address :



MasteringBizTalk.com
UsingBizTalk.com
TraceOfThought.net
MapPoint
Tomas Restrepo - Devdeo

 

If you can not view this newsletter, view it online at: http://www.biztalkgurus.com/newsletter/TheBizTalker-Volume-11.html

BizTalker

December 19th, 2007
Volume 11


     

Automatic Remove-All of BAM Definition During Uninstall of BizTalk Application
by Eric Stott

With the 2006 deployment paradigm shift, I have been kind of left behind.
I have lately been thinking a lot about how to make things better/easier/lazier for me, and it got me looking at the new automatic features in the creation of the MSI.
One of the things is the ability to deploy BAM definitions automatically. Let's review how this is done.

Note that you can click on the pictures below for a larger image.

  1. On the development server, you still need to manually deploy the BAM definition.
    bm deploy-all
  2. You then want to add the BAM definition file to your application as a resource. Some things to keep in mind, you need to make sure you define a destination, otherwise the BAM definition file does not exist on your next environment. I am using variables that are accessible from the BTSTask.
    BAM Resources
    Doing this will ensure a successful installation of your BAM definition on your new environment, congratulations! However the issue is that if you undeploy the BizTalk application, the BAM definition still exists and is not removed. I asked Keith Lim if this was a feature or flaw. He informed me that this was by design. "I checked with our feature team and this is indeed by design.  The reason is that, for BAM activity deployment, there could already be user data in the database tables and we don’t want to risk having user data deleted implicitly." -- Well, for me, most times I don't want to have to manually go to an environment that I normally don't have access to anyway and undeploy BAM definitions if I need to redeploy code, because 90% of the time I will want to start all over with BAM than keep working with the old data. I want a way to automatically undeploy the BAM definition! Here is how:
  3. Now you will need to add a script that will actually remove the BAM Definition. Let's first create the script (uninstall.bat) and then add it. The code below does the following, determines that it is undeploying and then undeploys the BAM definition
    @setlocal
    set LogFile=c:\%BTAD_ApplicationName%_Undeploy.log
    REM ### Uninstall part of the script called for an existing application
    if "%BTAD_ChangeRequestAction%"=="Delete" (
      if "%BTAD_InstallMode%"=="Uninstall" (
        if "%BTAD_HostClass%"=="BizTalkHostInstance" (
            echo "c:\Program Files\Microsoft BizTalk Server 2006\Tracking\bm.exe" remove-all -DefinitionFile:"%BTAD_InstallDir%\%1" >> "%LogFile%"
            "c:\Program Files\Microsoft BizTalk Server 2006\Tracking\bm.exe" remove-all -DefinitionFile:"%BTAD_InstallDir%\%1" >> "%LogFile%"
            echo "Pre uninstall part of the script called for %BTAD_ApplicationName%" >> "%LogFile%"
        )
      )
    )
    @endlocal


    Now you might ask yourself, "why don't you determine the path of the install directory right from within the batch file" like this:

    for /f "skip=2 tokens=2,*" %%f in ('reg query "HKLM\SOFTWARE\Microsoft\BizTalk Server\3.0" /v "InstallPath"') do SET BTSbm="%%~gTracking\bm.exe remove-all -DefinitionFile:"
    echo "%BTSbm%%BTAD_InstallDir%\%1" >> "%LogFile%"
    "%BTSbm%%BTAD_InstallDir%\%1"

    I tried for quite a while, but for some reason the logic will not resolve to the install path. If anyone knows why, I would be happy to add how to get it to work, in the meantime, go ahead and hard code the install path.
  4. Now you would think that you would simply add the batch file as a PostProcessingScript like this
    PostProcessingResource
    however there is no way to add an argument to the calling of this batch file (remember "%BTAD_InstallDir%\%1" ?) So we need to manually add it. We also need to make sure it is a PostProcessingScript, as the documentation states here: "During uninstallation, all scripts run in the opposite order that they run during installation. Therefore, post-processing scripts run at the beginning of uninstallation and pre-processing scripts at the end of uninstallation." - We don't want to delete the BAMDefinition.xml before the undeploy process gets to it do you?
  5. I need to add the batch script with an argument (the BAMDefinition.xml). I need to follow the instructions as documented here.
    (there is no way to add a pre or post processing script with arguments using the UI according to Microsoft)
      Import PostProcessing Script
  6. Let's go back and see the script has been added correctly
     updatedResouces
  7. Let's create the MSI and don't extract the Global Parties (since we don't care about them anyway)
     Create MSI Part 1
  8. Save the file
     Create MSI Part 4
  9. Now you can install it in your new environment. Having done that, just to make sure, lets take a look at the install directory to make sure the two files are there:
     Installed Files
  10. Also the BAM Views are there:
    BAM Views
  11. So lets undeploy the code and see if the magic happens! (Of course it would, or this blog entry would be a total sham!)
    EmptyBAM
  12. And finally the log that we created in the batch script
    UndeployLog

Congratulations, you now have a MSI that will deploy a BAM solution to the environment you need and will also undeploy the definition when you uninstall the application!

Wouldn't it be nice to have a dialog box during the uninstallation of a BizTalk application where there is a BAM component asking if we want to undeploy instead of these hoops?
My personal lessons learned:

  • Don't have spaces in the application name or the BAM Definition file: the BTSTask variables behave oddly and when passing variables into the batch file is almost impossible to troubleshoot

  • Even though I could run a batch file manually that would resolve the installation path of BizTalk, the resolving always came back as null

  • If it is a PreProcessingScript, it will delete the folder in the Program Files directory (and all subsequent files stored there) before executing the script

  • Even though it warns "You should always write scripts intended for production systems in silent mode. This is because a script waiting for user input will cause the BizTalk databases to become locked and inaccessible until the input is received." I had to test it, I put a pause in the batch file and I ended up rebooting the machine because the installation script was waiting for me to press a key on a DOS prompt that wasn't available!

About Eric Stott:
I excel at making easy things hard and hard things harder! (and write about them at http://blog.biztalk-info.com and http://blog.hl7-info.com). I am a BizTalk Server MVP. I also own a small Consulting Company specializing in BizTalk and related solutions for small to medium businesses. I am always FOR HIRE :). If you are in the need for consulting services, feel free to drop me a line through my blog.


QuickLearn

Go straight to the source and get BizTalk training from the company who developed the official BizTalk Server 2004/2006 courseware for Microsoft. We teach more BizTalk training than any other company in the world. To date, we have taught more than 4000 developers how to develop and deploy BizTalk integration and business process automation applications. Our instructors are experienced developers and the best trainers in the industry.

Here are the BizTalk Server 2006 R2 courses we currently offer:

BizTalk Server Immersion (for new BizTalk developers).
BizTalk Server Deep Dive (for experienced BizTalk developers).
BizTalk for Administrators (for IT Professionals)

QuickLearn can deliver onsite training at your facilities anywhere in the world. Click here for more information.


Updated BizTalk Community OPML Files
I have made some updates to the BizTalk Community OPML files I use to track BizTalk blogs. I now have an Active and an InActive List of BizTalk bloggers. In all, over 100 blogs covering BizTalk content.

You can download the latest OPML files here: http://www.biztalkgurus.com/opmlfeeds.aspx

Take a look at the OPML download page for a sneak peak at the new look of BizTalkGurus.com!


Comments or Suggestions?
I welcome comments, questions, and suggestions. After all, this newsletter is about delivering content you want to hear about! Feel free to contact me through the forum or via e-mail.

Until next time...
Stephen W. Thomas - BizTalkGurus.com

The Bottom Line:
I will soon find out if the water in the sink spins the other way in the Southern Hemisphere. I'm headed to Argentina in just a few days!

Netflix, Inc.SomeAd

Forum