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
<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>
<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 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:
The Current folder keeps the currently deployed build. The [YYYYMMDD_hh_mm_ss] folders keep the old builds.