In the previous post, I provide a fix to the PowerShell script that is able to configure the Deployment Properties of a BizTalk project, keeping my word, at least half of it, because I also found the same problems in the PowerShell script to fix or configure the Signing Properties of a BizTalk Project, i.e., it only worked if the signing properties already existed in the file(s) (.btproj). This means that:
- If we obtain a copy of the project from the source control that already has these properties defined, it will work; otherwise, the script will be unable to properly set these properties.
- If we were working on a new project, the script definitely didn’t set up the signing properties.
Again, I promised that I would fix it, and now I’m keeping the rest of my word. Along with the previous one, this is probably one of the scripts I use the most, and the reason is…
📝 One-Minute Brief
This post explains why strong‑naming BizTalk assemblies is mandatory before deployment and introduces a PowerShell v2 script that automatically configures Signing Properties for all projects in a Visual Studio BizTalk solution, including cases where signing settings don’t yet exist.
So, why is this script important?
Again, and this is nothing new, before deploying a BizTalk project, we must first strongly sign the assemblies involved in the project to give them unique identifiers that allow them to be installed in the GAC.
GAC (Global Assembly Cache) is a machine code cache that stores assemblies shared by multiple applications on the computer. These assemblies need to be strongly signed so they can be uniquely identified in the GAC.
A strong-named assembly provides several security benefits:
- A strong name guarantees the assembly’s uniqueness by assigning it a digital signature and a unique key pair.
- A strong name protects the assembly’s lineage by ensuring that no one else can generate a subsequent version.
- A strong name provides a strong integrity check to guarantee that the contents of the assembly have not changed since the last build.
During deployment of a BizTalk solution, Visual Studio first builds the assemblies. The deployment process requires that each assembly be strongly signed. You can strongly sign your assemblies by associating each project in the solution with a strong name assembly key file. That is an easy and rapid task (non-time-consuming task). However, if a solution in Visual Studio contains multiple projects, you must separately configure properties for each project.
This seems a slight and easy task, but now imagine that you have almost 200 projects inside a unique Visual Studio Solution! It will be an insane operation, and the most likely thing to happen is for you to fall asleep in front of the PC… once again.
With this PowerShell, you will be able to parameterize all projects inside a Visual Studio Solution running a single line of code and avoid spending numerous hours doing this task manually.
PowerShell script overview
$allPropertyGroup = $xml.Project.PropertyGroup
foreach($node in $allPropertyGroup)
{
if($node.AssemblyOriginatorKeyFile -ne $null)
{
$addNewKeyNodeFlag = $false;
$node.AssemblyOriginatorKeyFile= $keyName;
}
if($node.SignAssembly -ne $null)
{
$addNewSignNodeFlag = $false;
$node.SignAssembly= $true;
}
}
if($addNewKeyNodeFlag -eq $true)
{
$childItemGroup = $xml.CreateElement("PropertyGroup",$xdNS)
$childNone = $xml.CreateElement("AssemblyOriginatorKeyFile",$xdNS)
$childNone.AppendChild($xml.CreateTextNode($keyName));
$childItemGroup.AppendChild($childNone)
$xml.Project.InsertBefore($childItemGroup, $xml.Project.ItemGroup[0])
}
if($addNewSignNodeFlag -eq $true)
{
$childItemGroup = $xml.CreateElement("PropertyGroup",$xdNS)
$childNone = $xml.CreateElement("SignAssembly",$xdNS)
$childNone.AppendChild($xml.CreateTextNode($true));
$childItemGroup.AppendChild($childNone)
$xml.Project.InsertBefore($childItemGroup, $xml.Project.ItemGroup[0])
}
$allItemGroup = $xml.Project.ItemGroup.None;
foreach($node in $allItemGroup)
{
if($node.Include -eq $keyName)
{
$addKeyToSolutionFlag = $false;
}
}
if($addKeyToSolutionFlag -eq $true)
{
$childItemGroup = $xml.CreateElement("ItemGroup",$xdNS)
$childNone = $xml.CreateElement("None",$xdNS)
$childNone.SetAttribute("Include", $keyName)
$childItemGroup.AppendChild($childNone)
$xml.Project.InsertBefore($childItemGroup, $xml.Project.Import[0])
}
Download
THIS POWERSHELL IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND.
You can download Visual Studio: Fixing BizTalk Project Signing Properties with PowerShell from GitHub here:
Hope you find this helpful! If you liked the content or found it useful and would like to support me in writing more, consider buying (or helping to buy) a Star Wars Lego set for my son.