Click here to Skip to main content
Click here to Skip to main content

Copying a New Build to All Environments

, 24 Sep 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
A Target for MSBuild, which I use with BizTalk Deployment Framework (BTDF) for the BizTalk Server application deployment.

Introduction

A target for MSBuild, which I use with BizTalk Deployment Framework (BTDF) for the BizTalk Server application deployment. But it is pretty generic and can be used whenever you need to copy a folder structure (files and sub-folders) into several places simultaneously. 

Using the Code

This MSBuild target could be a part of the Deployment.btdfproj file (which is a file from the BTDF Deployment project). Also, you can add it to the BizTalkDeploymentFramework.targets file of to any .target file.

Points of Interest

Here, I have to do a double loop in the Copy with two items, NewBuildToCopy files and EnvironmentName.

Also, it generates a folder name in the [YYYYMMDD_hh_mm_ss] format.

Code

<!-- Copy a new deployment build to all environments and to a Personal share. 
  Before this rename a Current folder to the [CurrentDateTimeTime] to save an old build. 
  -->
<Target Name="AfterInstaller" AfterTargets="Installer">
  <PropertyGroup>
    <NewBuild>..\Deployment\bin\$(Configuration)</NewBuild>
    <CurrentDateTime>$([System.DateTime]::Now.ToString
    ("yyyyMMdd_hh_mm_ss"))</CurrentDateTime>
    <Shares>\\fileshares.domain.com\Shares\</Shares>
    <SourceCodeShare>\BizTalk\Deployment\$(ProjectName)</SourceCodeShare>
    <PersonalShare>Z:\Projects\BizTalk\GLD\Samples\Deployment\$(ProjectName)</PersonalShare>
  </PropertyGroup>

  <!-- Rename Current shares to the [CurrentDateTime]: -->
  <ItemGroup>
    <EnvironmentName Include="QA;STG;PROD"/>
  </ItemGroup>
  <ItemGroup>
    <CurrentShare Include="$(Shares)%(EnvironmentName.Identity)$(SourceCodeShare)" />
    <CurrentShare Include="$(PersonalShare)" />
  </ItemGroup>

  <Exec Condition="Exists('%(CurrentShare.Identity)\Current')"
         Command='Rename "%(CurrentShare.Identity)\Current" "$(CurrentDateTime)"'/>

  <ItemGroup>
    <NewBuildToCopy Include="$(NewBuild)\**\*.*">
      <Destination>%(CurrentShare.Identity)</Destination>
    </NewBuildToCopy>
  </ItemGroup>

  <!-- Copy the last build to the Current shares: -->
  <Copy Condition="@(NewBuildToCopy) != ''"
        SourceFiles="@(NewBuildToCopy)"
        DestinationFiles="@(NewBuildToCopy->
        '%(Destination)\Current\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target> 

History

That is a standard routine. I am developing a BizTalk Server application and use the BizTalk Deployment Framework (BTDF) for all my deployments. When an application is ready for testing, at the end, for production, the build files have to be deployed. Usually the BizTalk installation has several environments. For example, the environments can be: Development, QA, Staging, Production (here they are QA, STG, PROD). Sometimes less, sometimes more. The best practice is to keep all environments isolated of each other. So each environment keeps its deployment packages separately. That means, in my case, the build files should be copied to all environments.

A good practice is to save the old builds in case of rollback.

The folder structure for the builds looks like this:

image

The Current folder keeps the currently deployed build. The [YYYYMMDD_hh_mm_ss] folders keep the old builds.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Leo Gan
Web Developer
Canada Canada
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150302.1 | Last Updated 24 Sep 2013
Article Copyright 2013 by Leo Gan
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid