Creating Automated Build Script for BizTalk using MSBuild

I saw lots of people talking about BizTalk build automation scripts and they are mostly curious about how MSBuild can help fix things. I thought of sharing potential and my experience of writing automated build script using MSBuild tasks. I am expecting readers to have some fundamental understanding of MSBuild, if not then please have a quick study at following links –

https://msdn2.microsoft.com/en-us/library/ms171451.aspx

https://www.codeproject.com/books/msbuild.asp.

I am not going to talk about MSBuild itself or the best practices around MSBuild (that could be a separate article in itself) but I will talk about using MSBuild in BizTalk project related build automations.

Understand with Example

Let’s take a simple example. In a typical BizTalk 2006 implementation, you will like to do following build activities –

  1. Get latest code from source control
  2. Build solutions
  3. Create BizTalk Applications
  4. Add BizTalk resources (dlls, bindings etc.) to BizTalk applications.
  5. Import binding file to create ports and bind to orchestrations
  6. Export BizTalk application as MSI package (so that it can be deployed on testing/production machines)

Let’s see how MSBuild can help achieve this –

  1. Accomplishment of task <a> depends on source control used. It could be TFS, VSS, Source Depot anything. In general, we can use < ExecCommand = '<command>' /> MSBuild task to perform this job where command will use source control command line utility (e.g. TF.exe in case of TFS) to get latest code from source control database. Alternative, we can also use solution build framework (SBF) which provides VSS, source depot specific MSBuild task to perform job. We will talk about SBF later which is a wonderful extension over MSBuild. For example if TFS is the source control then we can use following command –

<Exec Command='"TF.exe get "$(TFSFolder)" /force /recursive'/>

  1. To execute task <b>, we can use exec task (<Exec />) along with Microsoft development environment command (devenv.exe). Example –

      <Exec Command='"devenv.exe" "TestSolution.sol" /Rebuild'  />

  1. Now comes the interesting part for any BizTalker. Tasks <c>, <d>, <e> and <f> can be achieved using two approaches – using MSBuild <exec> task with BizTalk command line utilities or using SBF. Lets see how first approach works –

Create BizTalk Application (Task <c>) example –

     <Exec

Command ='"$(BtsInstallLocation)\BTSTask" AddApp /ApplicationName:TestBtsApplication' />

Add BizTalk dll (Resource) to BizTalk Application (Task <d>) example –

<Exec Command ='"$(BtsInstallLocation)\BTSTask" AddResource /ApplicationName:TestBtsApplication /Type:System.BizTalk:BizTalkAssembly /Overwrite /Source:SampleOrchestration.dll /Options:GacOnInstall,GacOnImport'/>

Import Binding File to BizTalk Application (Task <e>) example –

<Exec Command ='"$(BtsInstallLocation)\BTSTask" ImportBindings /ApplicationName: TestBtsApplication /Source:SampleBinding.xml'/>

     

Export BizTalk Application into MSI package (Task <f>) example –

<Exec Command ='"$(BtsInstallLocation)\BTSTask" ExportApp /ApplicationName: TestBtsApplication /Package:TestBtsApplication.Setup.msi'/>

  1.  That’s it. With simple recipe of MSBuild tasks and BTS command line utilities, we can achieve most of the things we wish for build automation. This example is not end of world; you can accomplish numerous other tasks related to BizTalk application, resources, bindings, web service publishing etc. I suggest you to refer following links to realize other capabilities of BizTalk command line utilities.

https://msdn2.microsoft.com/en-us/library/aa559686.aspx

https://msdn2.microsoft.com/en-us/library/aa560399.aspx

Limitations

Are we done? Can we achieve everything using MSBuild tasks command line utilities? Unfortunately no because BizTalk does not offer command line utilities for many simple but much needed tasks such as start/stop BizTalk application, exporting schema, rule policies related tasks etc.

One solution is to use BizTalk Explorer Object Model to create custom MSBuild tasks (Implement ITask). Other is to reuse existing custom implementation done by others. And here comes Solution Build Framework in picture which is a brilliant in-house development done by MCS, UK.

Using Solution Build Framework (SBF)

You can find solution build framework at following location - https://www.gotdotnet.com/codegallery/codegallery.aspx?id=b4d6499f-0020-4771-a305-c156498db75e. SBF has extended MSBuild extensively to address wide variety of tasks including build/deployment related tasks for BizTalk 2006.

Just have a look at custom task list in attached text document. It is awesome.

To use SBF, you need to

Ø download it from above link

Ø Unzip task binaries (Microsoft.Sdc.Tasks.dll etc)

Ø Include task list file (“Microsoft.Sdc.Common.tasks” containing “<UsingTask/>” statements) in your script file.

Ø Finally start using SBF custom tasks in your script.

You can read help file (Microsoft.Sdc.Tasks Documentation.chm) to understand capability and usage of SBF tasks in details. SBF also provides guidelines and sample scripts for quick start and best practices.

 

Lets see how can we start a BizTalk application which is not possible with out of box BizTalk command line utilities –

<Import Project="Microsoft.Sdc.Common.tasks" />

<Target Name="StartBizTalkApplications">

<BizTalk2006.Application.Start Application="Test Application"/>

</Target>

There are still some tasks which cannot be done in SBF such as rule policies related tasks, schema publishing tasks etc and here field is open for people like us to fill the gap.

There are endless things which are demanded for automated build. Most of them can be done using MSBuild and SBF while for other we can use adhoc custom developed tasks or manual steps.

I suggest you to start using these capabilities in projects because they add tremendous value to team development environment. If you have any query/issue, please feel free to ping me on my blog.

Thanks!

SBF Custom Tasks List.txt