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

It is nothing new that before you can deploy a solution from Visual Studio into a BizTalk Application, you must first set project properties, especially the Server and the Configuration Database. Otherwise, two things may happen:

  • The deployment will fail when you try to deploy it through Microsoft Visual Studio or redeploy a previously deployed BizTalk project.
  • Or all the assemblies and all their artifacts will be deployed to an unwanted BizTalk Application (typically BizTalk Application 1)

Previously, I wrote two posts regarding how to fix the Deployment Properties of a Visual Studio BizTalk Project with PowerShell; you can learn more about them here and here. However, during a migration project this week, I realized that v2 was having a problem adding deployment properties to the file if they did not exist. So I created a new version of this script to solve those issues because this is probably one of the scripts that I use the most, and the reason why is…

So, why is this script important?

Well, if a solution in Visual Studio contains multiple projects, you need to manually configure the deployment properties for each project.

And you must keep in mind that these settings are under the Project User Options file(s) (“*.btproj.user”) that are typically not under source control. The reason is that the Visual Studio deployment feature’s primary focus is development environments, where one user’s settings might differ from another’s. And it will be up to you, or your client, to decide if you want these files to be checked in and available to all of the developers on your team. (You can read more about this here)

So, this seems a slight and easy task, but now imagine you have almost 200 projects inside a unique Visual Studio Solution! It will be an insane and consuming task to do, and most likely, you will fall asleep in front of the laptop.

With this PowerShell, you can 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

# Iterate all *.btproj.user files
Get-ChildItem -Recurse -Filter *btproj.user | ForEach-Object { 
    $path = $_.FullName
    $xml = [xml](Get-Content $path)

    $namespaceUri = "http://schemas.microsoft.com/developer/msbuild/2003"
    $nsmgr = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
    $nsmgr.AddNamespace("ns", $namespaceUri)

    # Find any existing PropertyGroup
    $propertyGroup = $xml.SelectSingleNode("//ns:PropertyGroup", $nsmgr)

    if ($propertyGroup -ne $null) {
        # PropertyGroup exists → update or add the necessary elements
        $properties = @{
            "Server" = $ServerName
            "ConfigurationDatabase" = $DatabaseName
            "ApplicationName" = $ApplicationName
            "Redeploy" = $RedeployFlag
            "Register" = $RegisterFlag
            "RestartHostInstances" = $RestartHostInstancesFlag
        }

        foreach ($key in $properties.Keys) {
            $element = $propertyGroup.SelectSingleNode("ns:$key", $nsmgr)
            if ($element -ne $null) {
                # Update existing element
                $element.InnerText = $properties[$key]
            }
            else {
                # Create new element if missing
                $newElement = $xml.CreateElement($key, $namespaceUri)
                $newElement.InnerText = $properties[$key]
                $propertyGroup.AppendChild($newElement) | Out-Null
            }
        }
    }
    else {
        # No PropertyGroup exists → create one and add all properties
        $newPropertyGroup = $xml.CreateElement("PropertyGroup", $namespaceUri)

        $properties = @{
            "Server" = $ServerName
            "ConfigurationDatabase" = $DatabaseName
            "ApplicationName" = $ApplicationName
            "Redeploy" = $RedeployFlag
            "Register" = $RegisterFlag
            "RestartHostInstances" = $RestartHostInstancesFlag
        }

        foreach ($key in $properties.Keys) {
            $element = $xml.CreateElement($key, $namespaceUri)
            $element.InnerText = $properties[$key]
            $newPropertyGroup.AppendChild($element) | Out-Null
        }

        $xml.Project.AppendChild($newPropertyGroup) | Out-Null
    }

Download

THIS SQL 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 towards purchasing a Star Wars Lego for my son!

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