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

  • Sandro Pereira
  • Aug 18, 2016
  • 4 min read

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 in Microsoft Visual Studio or when you redeploy a previously deployed BizTalk project.
  • The assemblies and all their artifacts will be deployed to an unwanted BizTalk Application (normally BizTalk Application 1).

Previously, I wrote a post regarding how to fix the Deployment Properties of a Visual Studio BizTalk Project with PowerShell; you can learn more about it here. However, during my discussions on tips and tricks, I realized that the previous script was a bit limited; it only worked if the deployment properties already existed in the file. This means that if we were working on a new project or obtained a copy of the project from source control, the script didn’t correctly set up or fix the deployment settings.

I promised that I would fix it, and now I’m keeping my word. And I have to say, this is probably one of the scripts I use the most, and the reason is…

📝 One-Minute Brief

This post explains why BizTalk Visual Studio deployments fail or deploy to the wrong application when Deployment Properties aren’t set. It then provides a PowerShell v2 script that automatically configures deployment settings across all projects in a solution—including cases where the .btproj.user properties don’t yet exist—saving significant manual effort. [blog.sandr…ereira.com]

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 stored in the Project User Options file(s) (“*.btproj.user”), which are typically not under source control. The reason is that the Visual Studio deployment feature main focus is for development scenarios where one user settings might differ from another. And it will be up to you or your client to decide whether you want these files to be checked in and available to all developers on your team. You can read more about this here.

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

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.Server -ne $null)
        {
            #If the Deployment Setting already exists, then we just need to update them
            $addNewNodeFlag = $false
            $node.Server= $ServerName;
            $node.ConfigurationDatabase= $DatabaseName;
            $node.ApplicationName= $ApplicationName;
            $node.Redeploy= $RedeployFlag;
            $node.Register= $RegisterFlag;
            $node.RestartHostInstances= $RestartHostInstancesFlag;
        }
    }

    if($addNewNodeFlag -eq $true)
    {
        #Add a PropertyGroup node if the Deployment Setting doesn't exist
        $newXmlPropertyGroup = $xml.CreateElement("PropertyGroup", "http://schemas.microsoft.com/developer/msbuild/2003")
        $newXmlPropertyGroup.SetAttribute(“Condition”,”'`$(Configuration)|`$(Platform)' == 'Debug|AnyCPU'”);

        $newXmlElement = $newXmlPropertyGroup.AppendChild($xml.CreateElement("Server", "http://schemas.microsoft.com/developer/msbuild/2003"));
        $newXmlTextNode = $newXmlElement.AppendChild($xml.CreateTextNode($ServerName));

        $newXmlElement = $newXmlPropertyGroup.AppendChild($xml.CreateElement("ConfigurationDatabase", "http://schemas.microsoft.com/developer/msbuild/2003"));
        $newXmlTextNode = $newXmlElement.AppendChild($xml.CreateTextNode($DatabaseName));

        $newXmlElement = $newXmlPropertyGroup.AppendChild($xml.CreateElement("ApplicationName", "http://schemas.microsoft.com/developer/msbuild/2003"));
        $newXmlTextNode = $newXmlElement.AppendChild($xml.CreateTextNode($ApplicationName));

        $newXmlElement = $newXmlPropertyGroup.AppendChild($xml.CreateElement("Redeploy", "http://schemas.microsoft.com/developer/msbuild/2003"));
        $newXmlTextNode = $newXmlElement.AppendChild($xml.CreateTextNode($RedeployFlag));

        $newXmlElement = $newXmlPropertyGroup.AppendChild($xml.CreateElement("Register", "http://schemas.microsoft.com/developer/msbuild/2003"));
        $newXmlTextNode = $newXmlElement.AppendChild($xml.CreateTextNode($RegisterFlag));

        $newXmlElement = $newXmlPropertyGroup.AppendChild($xml.CreateElement("RestartHostInstances", "http://schemas.microsoft.com/developer/msbuild/2003"));
        $newXmlTextNode = $newXmlElement.AppendChild($xml.CreateTextNode($RestartHostInstancesFlag));

        $xml.Project.InsertAfter($newXmlPropertyGroup, $xml.Project.PropertyGroup[1])
    }

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 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. 

Thanks for Buying me a coffe
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.

3 thoughts on “How to fix or configure the Deployment Properties of a Visual Studio BizTalk Project with PowerShell version 2”

  1. Hi,

    I don’t seem to be able to find this script at the specified location. Do you know if it was moved somewhere else?

    Thank you,
    Sergio

    1. Hi Sergio,
      I need to update all my links. TechNet Gallary is deprecated.
      I update the link to the new GitHub repository where I have all my resources

Leave a Reply

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

The Ultimate Cloud
Management Platform for Azure

Supercharge your Azure Cost Saving

Learn More
Turbo360 Widget

Back to Top