다음을 통해 공유


BTDF: Using multiple PortBindingsMaster.xml files.

There are some cases where we need different BizTalk artifacts for different environments under the same application. E.g. same application with different receive locations for different environments.  There are couple of ways to achieve this using BTDF and today I am going to discuss the simplest and the easiest way, by using multiple PortBindingsMaster.xml files.

Let’s consider a case where a BizTalk application (Application1) has multiple orchestrations receiving messages from same receive port having multiple receive locations. The number of receive locations differ as per the environment. Environment E1 needs 3 receive locations and E2 needs 2 receive locations. If we go with the single PortBindingsMaster.xml then we need to make sure to disable unused receive locations or create new in that environment.  So here, we can create two different PortBindingsMaster.xml for environment E1 and E2 to avoid any manual intervention, after deploying the application.

Now the question is, how to use multiple PortBindingsMaster.xml files in BTDF? And the answer is simple, by replacing Original PortBindingMaster.xml by environment specific PortBindingsMaster.xml file.

Follow the steps to know how to replace original PortBindingsMaster.xml with ,

  1. Create PortBindingsMaster.xml file for each environment. Here for environment E1 create PortBindingsMaster_E1.xml and for E2 create PortBindingsMaster_E2.xml. 

  2. Create a MasterBindings folder under deployment project folder and keep all environment specific PortBindingsMaster.xml files inside this folder.

  3. Update PortBindingMaster_E1.xml with environment E1 bindings (3 receive locations) and PortBindingMaster_E2.xml with environment E2 bindings (2 receive locations). Keep one thing in mind, we are trying to handle number of artifacts required by each environment and not the configuration of the artifacts itself. So we still need SettingsFileGenerator.xml to replace environment specific receive location properties. e.g. ReceiveHandlers.

  4. Add environment specific PortBindingsMaster.xml files to the deployment package.

       <ItemGroup Label = "MasterBindingFiles">
        <AdditionalFiles Include = "PortBindingsMaster_E1.xml">
          < LocationPath> MasterBindings\ </LocationPath >
         </AdditionalFiles >
          <AdditionalFiles Include = "PortBindingsMaster_E2.xml">
          <LocationPath> MasterBindings\ </LocationPath>
         </AdditionalFiles>
     </ItemGroup>

  5. Now we need to replace PortBindingMaster.xml under Deployment folder (C:\Program Files (x86)\BizTalk – Application1\1.0\Deployment) after installation. We can do this by using simple dos commands before PreprocessBindings target. PreprocessBindings target uses PortBindingMaster.xml and SettingsFileGenerator.xml to create PortBindings.xml which will be used to import binding at the end. Add following custom targets to BTDF project,

       <Target Name = "CopyMasterBindings" BeforeTargets = "PreprocessBindings">
        <Exec Command = "if not exist MasterBindings (mkdir MasterBindings)">
        <Exec Command = "if exist ..\PortBindingsMaster*.xml (move /y ..\PortBindingsMaster*.xml MasterBindings/)">
     </Target>
       <Target Name = "OverwriteEnvironmentSpecificMasterBindings" AfterTargets = "CopyMasterBindings">
        <Exec Command = "copy /y MasterBindings\PortBindingsMaster_$(ENVT).xml PortBindingsMaster.xml">
     </Target>                                  

    The target CopyMasterBindigs will help to keep all the PortBindingMaster.xml to a single file location (here by creating MasterBindings folder under Deployment folder) to handle them properly and thereafter OverwriteEnvironmentSpecificMasterBindings target will replace PortBindingMaster.xml from Deployment folder by the Environment specific port binding master file from MasterBindings folder. We can use a custom variable to find environment specific bindings file. Here we are using variable ENVT. This variable can hold E1 or E2 string values.

  6. Now we need to initialize the ENVT variable and assign environment specific value to it. This can be done by adding UI controls to InstallWizard.xml file. We can use radio button UI controls to select environment. Add following UI configuration item to InstallWizard.xml under SetEnvUIConfig,

       <SetEnvUIConfigItem>
          <PromptText> Select Environment to choose PortBindingMaster file</PromptText>
          <PromptValue> E1</PromptValue>
          <ValueType> RadioButtons</ValueType>
          <EnvironmentVarName> ENVT</EnvironmentVarName>
             <RadioPrompts>
              <string> Environment_1</string>
              <string> Environment_2</string>
             </RadioPrompts>
             <RadioValues>
              <string> E1</string>
              <string> E2</string>
              </RadioValues>
    </SetEnvUIConfigItem>

Your comments would be appreciated.

Thank you