Importing and Exporting MSI files from or to a BizTalk application using BTSTask command in BizTalk

Introduction -

Hi everyone, in this post I will explore the process of Importing and Exporting MSI files to/from a BizTalk application using the BTSTask command.
  
Description -

The above tasks of importing/exporting are accomplished using the command BTSTask in this post.
The same can be done using the BizTalk administration console also, the reason I am using the command prompt is to get familiar with the usage of the command BTSTask, which is one of the most widely, used commands by BizTalk administrators.

Advantage of using the command prompt is that we can automate these tasks by using a batch file/Windows scheduler. I will try to explain this automation in one my future posts.

Note-
a) The name of the application used in this example is BizTalkTestApplication and it’s a completely configured application.
b) All the below commands can be run on visual studio command prompt or a normal command prompt.
c) The visual studio command prompt can be accessed in the following path.
Start->All Programs->Microsoft Visual Studio->Visual Studio Tools->Visual Studio Command Prompt

d) The below points apply to the usage of the command
i) ApplicationName_value is the name of our BizTalk application to be imported into or exported.
This is a optional parameter. If no name is specified then it will be export  the default BizTalk application and be imported into the the default application i.e. “BizTalk Application 1” .
If the name includes spaces, it must be enclosed with double quotation marks "  ie if we wanted the application name as Biz Development Application then we need to write the as
–ApplicationName: "Biz Development Application”  .

ii) Package_value - The absolute path along with the name of the MSI file to be exported or from where it needs to be imported. This is a mandatory parameter.

iii) Server_value - The name of the SQL Server instance hosting the BizTalk Management database, in the form ServerName\InstanceName,Port. This is an optional parameter.
Instance name is required when the instance name is different than the server name.
Port is required when SQL Server uses a port number other than the default (1433).
Examples:
Server=MyServer
Server=MyServer\MySQLServer,1533
This is an optional parameter, hence If not provided, the name of the SQL Server instance running on the local computer is used.
The database parameter is mandatory if the server parameter is specified.

iv) Database_value – Here the name of the BizTalk Management database needs to be specified.
This is an optional parameter and If not specified, the BizTalk Management database running in the local instance of SQL Server is used ie BizTalkMgmtDb.

v) Overwrite – This option is used to overwrite artifacts in the application with artifacts in the .msi file that have the same locally unique identifier (LUID).


Exporting a BizTalk application

To export a BizTalk application as a MSI File we need to use the BTSTask command with the following syntax

Syntax:  BTSTask  ExportApp  -ApplicationName:value  -Package:value  -ResourceSpec:value
-GlobalParties   -Server:value -Database:value
or
Syntax:  BTSTask  ExportApp  -A:value  -P:value  -R:value -GlobalParties   -S:value -D:value

The below example exports the application “BizTalkTestApplication” as MSI Files at the path specified in the parameter “Package” ie in the C: Folder with the name BizTalkTestApplnMSIFiles.

Example:  BTSTask  ExportApp -ApplicationName:BiztalkTestApplication  -Package:C:/BizTalkTestApplnMSIFiles.msi


Importing a BizTalk application

To import a BizTalk application into the configuration database the BTSTask command needs to be executed with the following syntax

Syntax:  BTSTask ImportApp -ApplicationName:ApplicationName_value  -Package:Package_value  -ResourceSpec:ResourceSpec_value  -Server:Server_value -Database:Database_value –Environment:Environment_value -Overwrite
or
Syntax : BTSTask ImportApp -A:ApplicationName_value  -P:Package_value  -R:ResourceSpec_value  -S:Server_value -D:Database_value –E:Environment_value -O

Note – The application must be stopped before importing.

The below example imports the application “BizTalkTestApplication” into the configuration database of the SQL Server

Example:  BTSTask ImportApp -Package:C:\BizTalkTestApplnMSIFiles.msi  -ApplicationName:BizTalkTestApplication –Overwrite

Note - The above commands adds the application into the configuration database and not into the GAC, it needs to be added into GAC separately for the application to work properly.

Host instance needs to be restarted for the application to run properly after the above step.

Note -
i) Here when we import using the BTSTask command, we are registering in the BizTalk configuration database, we need to install the assemblies into the GAC also to run the application.

ii) We can get help about the commands in command prompt by typing in the command as follows
BTSTask ExportApp -?
BTSTask ImportApp -?

iii) The below tasks can be done only using the BizTalk Server Administration console
a) Start or stopping an application.
b) Change the state of an artifact: start, stop, enable, disable, enlist, and unenlist.
c) Edit artifact properties.
d) Create a send port, send port group, receive location, or receive port.

Further Reading

BizTalk  Run time Architecture