Using Pre- and Post-Processing Scripts with BizTalk

No revolutionary news today, but I thought I would share my thoughts on a probably well known but seldom used feature.

Indeed, as part of the deployment and installation of an application from a Windows Installer package, it is possible to perform additional operations in the form of pre-processing and post-processing scripts. Often overlooked in most projects I have been working on, this capability is really interesting to help automate the deployment as much as possible and make the experience for systems administrators smoother.

In order to leverage this capability, the scripts must be deployed to the BizTalk application in the form of resources with types System.Biztalk:PreProcessingScript and System.Biztalk:PostProcessingScript respectively. These scripts will therefore also be present inside the .msi installation package after export.

One thing to note is that these scripts accept arbitrary input parameters in the form of a command-line string. However, this is not available from the the BizTalk Server Administration Console. As far as I know, the only way to specify a command-line for pre- and post-processing scripts is via the BtsTask.exe command-line utility:

BTSTask AddResource [/ApplicationName:value] /Type:System.BizTalk:PreProcessingScript|System.BizTalk:PostProcessingScript [/Overwrite] /Source:value [/Destination:value] [/Server:value] [/Database:value][/Property:Args="argument list"]

There is no limitation to what programming language can be used to author pre- and post-processing scripts. Indeed, any kind of "executable" artifact can be used as long as it can be launched directly on the target platform. In particular, this lets you write scripts as .bat or .cmd command processor batch files, .vbs or .js WSH-powered scripts, or even full blown .exe windows executables.

During their execution, those scripts have access to a useful set of environment variables that are set by the BizTalk installation subsystem. In particular, the following three variables are useful in order to perform additional tasks using the btstask.exe command-line utility :

  • btad_applicationname: set to the name of the corresponding BizTalk application,
  • btad_server: set to the name of the SQL Server instance that hosts the BizTalk management database,
  • btad_database: set to the name of the associated BizTalk management database.

It would be tempting to use PowerShell scripts in this case. However, on most target platforms, even though PowerShell is present, the .ps1 file extension is not registered as an "executable" file type. Unless this registration is updated, it is only possible to call PowerShell scripts from other scripts written in one of the supported programming languages mentioned above.

For instance, one useful usage of these scripts would be to implement proper uninstallation logic in order to remove assemblies from the GAC, which seems like a curious oversight from the BizTalk team.

Another usage would be to add XRef messages to the BizTalk management database, using a SQL script.

This entry was posted in BizTalk. Bookmark the permalink.