Following last week’s blog post about the nightmare exportation story, where we were finally able to get the assemblies for each BizTalk Server application in local folders – DLLs that were exported from the Global Assembly Cache (GAC). That means we do not have the MSI to install and import directly into the BizTalk Administration Console. We now have the challenge of installing and registering those assemblies 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)
}
}
}
Everything seems to work, and in some cases it will work, but I forgot a significant limitation: installation dependencies. In BizTalk Server, we need to make sure we install the schemas and maps first, and only then the orchestrations. We also need to make sure that if an assembly references another assembly, like common artifacts, we need to install them first! So, basically, I had to have an installation plan guide to script these tasks… another nightmare, since I didn’t have the big-picture view of all these dependency chains.
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!