25 March 2007

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 –

 

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

 

http://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 <Exec Command='<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.

 

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

 

http://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 - http://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!

Filed under:
 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# David Sidlinger said:

Brajendra,

While I think that any little bit helps, I think the solution you present is not acceptable long-term.  The complete lack of BizTalk integration with MSBuild (or anything else in VS.NET, for that matter) should be embarrassing for the BTS development team.

If Microsoft wants great development shops to use BTS, the BTS PMs and developers should start caring about things that great development shops care about (e.g. automated builds, unit testing, etc.).

23 April 07 at 9:11 AM
# John Dhom said:

You wouldn't typically have vs.net installed on a build server. You _should_ be able to script the build without having to resort to vs.net. Same goes for the need to install BizTalk on a build server. Developer licenses/installs are understandable... but not build server licenses/installs.

Best,

John Dhom

30 April 07 at 4:28 PM
# Brajendra Singh said:

John, you are not required to have vs.net installed on build machine. .net framework 2.0 is sufficient. you can write these scripts on dev machine using vs.net or on build machine using notepad/wordpad etc.

Similarily developer license on build machine is sufficient.

27 May 07 at 8:29 AM
# David Sidlinger said:

Brajendra,

How would you get around having Visual Studio installed on the build server?  Your example shells out to Visual Studio to perform the build.

Are you implying that the build should only run on the developer workstation?  What about CI builds?  Our company (and I'm sure Microsoft as well) does not deploy software built on a developer machine.

The fact of the matter is that "normal" .NET software can be built on a machine with only the SDK installed and BizTalk does not have a similar facility.

Lame.

27 May 07 at 10:11 AM
# Brajendra Singh said:

You are right. I hope Microsoft will standardize BTS project to make compatible with msbuild. Then SDKs would be sufficient to run build script on any machine.

27 May 07 at 11:15 AM
# Rachana said:

Hi,

I am trying to do an automated build and deploy of my biztalk solution using Cruise control.net.i have installed .net as well as biztalk (not configured) on my build server.

i am trying to execute the command line utility "Command='"devenv.exe"" for build. However,it is still not building the biztalk dll's.

Any suggestions for automating and build and deploy of biztalk solution.?

21 June 07 at 2:20 PM
# Brajendra Singh said:

Hi Rachana

What error you are getting when trying to build using devenv command?

28 June 07 at 12:52 PM
# rachana said:

Thanks BJ. My Automated build and deploy is working fine.I had to use "Command='"devenv.com" and it worked.yopur article was a great starting point.

16 July 07 at 4:22 PM
# Sulaiman said:

Hi BJ

Just happend to see ur blog on the MSBuild .

I am very happy & surprised to see your artcile & Rachana's comments.

Thanks & Regards,

Sullu

31 March 08 at 5:44 AM
# Mikael Håkansson said:

Hi Brajendra,

Thanks for the input, I'm trying to get the build process working with tfs and biztalk, but I'm still out of luck. Would you mind posting an entire sample of the tfsbuild.proj file.

regards

//Mikael

02 June 08 at 7:14 AM

Leave a Comment

Comment Policy: No HTML allowed. URIs and line breaks are converted automatically. Your e–mail address will not show up on any public page.

(required) 
(optional)
(required) 

  
Enter Code Here: Required
Page view tracker