%BTAD_InstallDir% not working in AddResource Command (BTSTask.exe)

Posted on Updated on

The global environment variable %BTAD_InstallDir% does not translate as you would expect when you AddResource using BTSTask.exe

in a batch command or in build event of assemblies.

A command such as :

BTSTask AddResource -Source:”$(TargetPath)” -ApplicationName:AppName -Type:System.BizTalk:Assembly -Overwrite  -Destination:”%BTAD_InstallDir%\$(TargetFileName)” -Options:GacOnInstall

is executed successfully but when you see the same in BizTalk admin console you find that its translates only to \$(TargetFileName) and the environment variable is skipped.

MSDN link suggests the same but that does not work.



To make this working use the below.

BTSTask AddResource -Source:”$(TargetPath)” -ApplicationName:AppName -Type:System.BizTalk:Assembly -Overwrite  -Destination:”%%BTAD_InstallDir%%\$(TargetFileName)” -Options:GacOnInstall

Note the two % symbols. This is because single % is skipped in evaluation.



BizTalk 2013 Map Issue and Resolution (.NET XSLCompiledTransform omen)

Posted on

The other day I was doing migration of some of the application from BizTalk 2010 to BizTalk 2013 and after successful migration, there was an issue while testing few maps. The same map which worked perfectly as expected in 2010 were not so happy in 2013.

After looking through the same the issue was found. Went on though lot search and reads, found some interesting news.

There has been a drastic change in how maps are executed in BizTalk 2013. With the new version on BizTalk Microsoft has introduced .NET XSLCompiledTransform in place of .NET XSLTransform for the mspping engine.

With this in, there has been performance improvement and memory utilization improvements.

But this major change in the product has potential, to make your existing old version maps fail under certain circumstances.

The cases being :

1. If the map is using custom scripting functoid which has boolean parameter. Please refer HERE.

2. If the map has Extension Objects and Script Functions with certain implementation. Please refer HERE.

There is a great post here explaining the details. 

As explained in the KB article.:

For example, consider the following code within a scripting functoid:

public int AddIfTrue(int param1, int param2, bool addNum)
    if (addNum) return param1+param2;
    else return param1;

In BizTalk Server 2013, the behavior is as follows:

  • If addNum is true, false, or any other value the output is param1+param2
  • If addNum is empty the output is param1

In prior versions of BizTalk, the behavior was as follows:   

  • If addNum is false the output is param1
  • If addNum is true, the output is param1+param2
  • If addNum is empty or any other value the functoid fails with error “String was not recognized as a valid Boolean”

In order to revert to the previous behavior, the scripting functoid code can be modified to take a String parameter instead of Boolean and then convert the String to Boolean within the functoid code as follows:

public int AddIfTrue(int param1, int param2, string addNum)
    bool addNumBool = System.Convert.ToBoolean(addNum);
    if (addNumBool) return param1+param2;
    else return param1;

It is also possible to configured the BizTalk 2013 Transform Engine to use the older XSLTransform class. This approach is not recommended since the environment will lose the many performance and memory usage improvements provided by the XSLCompiledTransform class. This change can be made by adding DWORD UseXslTransform with value 1 at the following locations:   

  • For 64 bit BizTalk host instances: HKLM\SOFTWARE\Microsoft\BizTalk Server\3.0\Configuration
  • For 32 bit BizTalk host instances and Visual Studio’s Test Map functionality: HKLM\SOFTWARE\Wow6432Node\Microsoft\BizTalk Server\3.0\Configuration

So, we just need to keep an eye on this when we are doing migrations. 



Read documents from SharePoint programmatically using C# (Perform a non deleting BizTalk WSS Recieve)

Posted on Updated on

Documents from SharePoint can be read programmatically using C# WebRequest.

On  a BizTalk front, such need occurs when you want to perform a non deleting receive for a sharepoint document.

Consider a scenario where your business process gets triggered and then within needs to read data from sharepoint document library and use it in the process.

BizTalk by default will delete the document from the library after reading the same. One can argue that we can implement a process within, where in the BizTalk  process will read the document and then put it back to the location through a WSS send port and we are done. This is absolutely fine and works as expected but as you see it has more over heads and more failure point. What if while uploading the document it fails and the nest process never gets to read the data and hence resulting in subsequent failures of the main business process. And above all you still need to have a C# code to activate , deactivate your receive location.

What comes in handy in such business scenario is that we can have the Sharepoint location read from a config, preferably SSO Config and then use C# code to read the data to stream or memory stream and then use the same within our business process.

Using memorystream would also help load it to BizTalk XLAng message. Also we can implement a full BizTalk streaming mechanism here to preform our action using IStreamfactory.  More details on this can be found here .

Using the below code we can read the contents to a stream and then to memorystream. UseDefaultCredentials will run the program under current user account or in BizTalk Orch case, under the BizTalk host instance account. So make sure that the user has sufficient rights to read the document library.

We can also key in specific user under the credentials of the request if desired so. Capture

Install MSI packages (Locally and on Remote computers) using WMI

Posted on Updated on

Installing of packages and msi is a day to day activity in current business scenario. And with growing use of technology and programs it becomes all the more important to have this process efficient, error free, less time consuming. Automating such process becomes all the more important.

Today we will see how we can achieve the same. WMI comes with great feature to leverage it and automate our msi installation process.

WMI namespace — root\CIMV2 has a class – “Win32_Product” which has few methods that work on msi packages. The methods being: —Admin, —Advertise, —Configure, —Reinstall, —Install, —Uninstall,–Upgrade

We will take a look at the Install method to achieve our goal. We can use WMI for automated installation either on a single machine, locally or on a group of machines.


Doing a local computer Installation can be done straight forward with the package location assigned to inParams.

The key here for remote multi machine installation is the “CopyToTempLocation” method that copies the msi from the machine on which the program is running to a local location on the specified remote machine and the new path is then set to inParams.

The outParams[ReturnValue] return the code .i.e the result of execution. There is a comprehensive list of codes returned and the one we should be looking for is  Zero“0” which implies success.

Please visit http://support.microsoft.com/kb/304888 to see the list of codes returned.


Cross Domain WCF-SQL Adapter communication

Posted on Updated on

For cross domain WCF-SQL adapter communication between servers that communicate, the UseAmbientTransaction property should be set to false to establish the data communication.



For detailed information of various WCF-SQL adapter properties please refer this.


BizTalk 2013 and SharePoint 2013 Integration Issue (401:Unauthorized)

Posted on Updated on

During the initial set-up of SharePoint 2013 adapter with BizTalk 2013 there may be scenario when you get errors such as  : The remote server returned an error: (401) Unauthorized.


The adapter failed to transmit message going to send port “XXXX” with URL “wss://ServerXXX:XX/sites/XX/xxxxx/xxxx“. It will be retransmitted after the retry interval specified for this Send Port. Details:”[System.Net.WebException] The remote server returned an error: (401) Unauthorized.

This error was triggered by the Windows SharePoint Services receive location or send port with URI “wss://ServerXXX:XX/sites/XX/xxxxx/xxxx“.

Windows SharePoint Services adapter event ID: 12310”.

When validating you see that the user under which the adapter host is running has all the rights on the web site and the document library and still you see the issue.

Out of curiosity the user is given rights on SharePoint database and WS_WPG groups also but still the problem persists.

The problem here is because the user is not having access to the root of the SharePoint server. In this case to http://ServerXXX:XX.

When BizTalk 2013 WSS adapter tries to access the document library it first tries to access the root and then dives in to the libraries for the action. A look at the SharePoint logs will give the necessary information.

Once the user under which the host of WSS adapter is running gets access to the root site, BizTalk 2013 will start communication to and from SharePoint document libraries. The permission can be the least privileged one .i.e Visitors.

Extract details of resources contained within a BizTalk MSI package

Posted on

There are multiple ways to extract details of resources contained within a BizTalk MSI package. One being using msiexec.exe to extract the contents to a location and get the information.

However BizTalk has an excellent dll which can help get all the required resource details that comes in packed in the MSI package.

The saviour here is

Microsoft.BizTalk.ApplicationDeployment.dll that comes with BizTalk installation.

Two dlls are required to be referenced :

1. Microsoft.BizTalk.ApplicationDeployment.dll which has the method that scans for you the MSI for all its resources and then the related properties within each resource. Its placed under the root BizTalk installation folder.

2.Microsoft.BizTalk.Admin.dll from GAC


 Microsoft.BizTalk.ApplicationDeployment.IInstallPackage pack = null;

pack = Microsoft.BizTalk.ApplicationDeployment.DeploymentUnit.ScanPackage(“FullBizTalkMSIPath”);

// Gets all the information about all the resources compliled witin BizTalk MSI package

Microsoft.BizTalk.ApplicationDeployment.IDeploymentResource[] resources = pack.Resources;

foreach (var resource in resources  )

{    // Do something     }