Following last week’s blog post about the nightmare exportation story, we finally extracted all assemblies for each BizTalk Server application into local folders. These DLLs came directly from the Global Assembly Cache (GAC).
Because of this approach, no MSI packages were available. As a result, we could not import the applications directly through the BizTalk Administration Console. This situation introduced a new challenge: installing and registering all assemblies manually in each BizTalk Server application.
📝 One-Minute Brief
This is a PowerShell script that goes to a folder containing assemblies and install and register them in a specific BizTalk Application.
If we are speaking about a few assemblies, we can easily install and register them manually; however, in my case, we were speaking of at least 400 assemblies, which was an insane amount of work and carried a considerable risk of needing to repeat these tasks in the near future.
So, with that in mind, and taking this in a controlled manner, I decided to create the following PowerShell script that:
- Give a local folder that contains the BizTalk Application assemblies and the application name
- It goes to all these DLLs, and for each, it installs it in the GAC and registers it in the BizTalk Server databases for that specific application.
Here is a sample of the script:
foreach ($dll in $dlls) {
$args1 = @(
'AddResource',
"/ApplicationName:$AppName",
'/Type:System.BizTalk:BizTalkAssembly',
'/Overwrite',
"/Source:`"$($dll.FullName)`"",
'/Options:GacOnAdd,GacOnInstall,GacOnImport'
)
$r1 = Start-Process -FilePath $BTSTask -ArgumentList $args1 -NoNewWindow -PassThru -Wait
if ($r1.ExitCode -eq 0) {
$results += [pscustomobject]@{ File=$dll.Name; Path=$dll.FullName; Result='Added+GAC' }
Write-Host ("OK -> {0}" -f $dll.Name) -ForegroundColor Green
} else {
# 2) Retry as plain .NET Assembly (helper libraries)
$args2 = @(
'AddResource',
"/ApplicationName:$ApplicationName",
'/Type:System.BizTalk:Assembly',
'/Overwrite',
"/Source:`"$($dll.FullName)`"",
'/Options:GacOnAdd,GacOnInstall,GacOnImport'
)
$r2 = Start-Process -FilePath $BTSTask -ArgumentList $args2 -NoNewWindow -PassThru -Wait
if ($r2.ExitCode -eq 0) {
$results += [pscustomobject]@{ File=$dll.Name; Path=$dll.FullName; Result='Added+GAC' }
Write-Host ("OK -> {0}" -f $dll.Name) -ForegroundColor Green
} else {
$results += [pscustomobject]@{ File=$dll.Name; Path=$dll.FullName; Result="ERROR ExitCode $($p.ExitCode)" }
Write-Warning ("FAIL -> {0} (ExitCode {1})" -f $dll.Name,$r2.ExitCode)
}
}
}
Although the script worked in many scenarios, I overlooked a critical limitation: assembly dependencies. In BizTalk Server, you must install schemas and maps first. Only after that can you install orchestrations.
Assembly references introduce another requirement. If an assembly depends on common or shared artifacts, those assemblies must already exist. Otherwise, the installation fails.
Because of this, I needed a clear installation order. That meant creating an installation plan to script each step correctly. Unfortunately, I did not have a complete view of all dependency chains. This lack of visibility quickly turned the process into yet another nightmare.
This resource is still valid, but I need another approach!
Download
THIS POWERSHELL SCRIPT IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND.
You can download the PowerShell Script used from GitHub here:
Hope you find this helpful! If you enjoyed the content or found it useful, and wish to support our efforts to create more, you can contribute to purchasing a Star Wars Lego set for my son!