Tallan's Technology Blog

Tallan's Top Technologists Share Their Thoughts on Today's Technology Challenges

Deploy BizTalk policy using command line tool

Leo Wang

As I discussed in my previous blog, manually deploying BizTalk application is error-prone. For every BizTalk application, developing a script to automate deployment process is absolutely necessary. One of recent projects I’m working on requires to import and deploy policies with multiple rulesets and vocabularies. BTSTask , a command line tool from Microsoft, can be used to accomplish this task.

For example

BTSTask ImportApp /Package: “C:\MSIFiles\MyApplication.msi” /Environment: Test /ApplicationName:MyApplication /Overwrite

For detail steps about how to use BTSTask to import policy, click here.

Although BTSTask works, it demands policies are stored in an MSI file. This is not desirable because it’s not easy to compare different versions in binary format. Ideally, I would like to import an XML file. Luckily Microsoft provides a sample console application, which almost can fulfill my requirement. You can download the tool ( ImportExportRuleStore.exe ). Please note, you need to compile it using Visual Studio.Net 2005.

With this tool I can import XML policy file. Here is detail usage information by entering “ImportExportRuleStore.exe /?”

     -import <filename>
     -export <filename> [ -rulesets <rulesets> | -vocabulary <vocabularies> ] Additional options:
     -server <server>
     -database <database>
     -addreferencedvocabularies<rulesets> are specified as <policyname>:<majorversion>.<minorversion>
<vocabularies> are specified as <vocabularyname>:<majorversion>.<minorversion>
If version is not specified, all versions of the policy/vocabulary are exported
Only the first letter of each option is necessary.
     ImportExportRuleStore -import sample.xml
     ImportExportRuleStore -i sample.xml -s (local) -d BizTalkRuleEngineDb
     ImportExportRuleStore -export sample.xml -rulesets Policy1 Policy2:1.0
     ImportExportRuleStore -e sample.xml -r Policy1:3.5 -v MyVocabulary:1.0

Unfortunately, there is a minor glitch. It doesn’t publish policy so I can not add policy into my BizTalk application using script. If I need to manually change the policy status from “Not Published” to “Published”, then obviously it is not acceptable. The good news is I have source code. By changing line 261 of program.cs file from databaseStore.Save(rulesetsToImport) to databaseStore.Save(rulesetsToImport,true), I can publish policies successfully.
Once the last issue is resolved, I can simply wrap the tool using MSBuild EXEC task to import BizTalk policies automatically.

<!– Import policy file –>

<Target Name=ImportPolicy >

<Exec Command =“$(BTSTools)\ImportExportRuleStore” -$(BindingFilePath)\$(PolicyFileName)/>


<!– Add Policy to BizTalk application –>

<Target Name=AddPolicy>

 <Exec Command =“$(BTSPath)\BTSTask” AddResource /ApplicationName:$(BTAppName) /Type:System.BizTalk:Rules /Name:$(PolicyName)



Tags: BizTalk,

Related Articles

The BizTalk Convergence
Passwords & BizTalk
Cleaning up BizTalk Databases

No comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>