How to fix or configure the Signing Properties of a Visual Studio BizTalk Project with PowerShell version 2

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 has already have these properties defined, it will work otherwise the script was unable to properly set these properties.
  • if we were working on a new project then definitely the script 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, this is probably one of the scripts that I use the most, and the reason why is…

So, why this script is 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 a unique identification for allowing them to be installed into the GAC.

GAC (Global Assembly Cache) is a machine code cache that stores assemblies that can be shared by multiple applications on the computer. These assemblies need to be strongly signed so that they can have unique identification in the GAC.

A strong-named assembly provides several security benefits:

  • A strong name guarantees the uniqueness of the assembly by assigning a digital signature and a unique key pair.
  • A strong name protects the lineage of the assembly by ensuring that no one else can generate a subsequent version of the assembly.
  • A strong name provides a strong integrity check to guarantee that the contents of the assembly have not changed since the last build.

In the process of deploying a BizTalk solution, Visual Studio first builds the assemblies. The deployment process requires that each assembly is 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 to happen are 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:

Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.

Leave a Reply

Your email address will not be published. Required fields are marked *

turbo360

Back to Top