Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSDeploy all configuration [.config files] in one package

We have 4 different environments at the moment (Lab, Test, Stage, LIVE) and we have implemented automatic deployment using Nant/CC.Net. I am investigating and doing some research as to what can be done more efficiently with new MSDeploy tool.

What I want to achieve is to create a package with a Configuration folder inside which we will have all the different configuration files for all the possible environments (basically adding all config transform files)

What I want to achieve is automatic deployment in our enterprise environment where development team hasn't got any access to the server where it is going to be deployed. We just need to hand over the deployment package with predefined instruction to how to install the package.

What's the best approach you can think of. WE ARE NOT USING TFS and don't want the automatic build process to be dependent on any process as such except MSDeploy or something which is easy to replace. Thinking of using MSBuild too.

like image 363
DotNetInfo Avatar asked Jun 15 '11 01:06

DotNetInfo


1 Answers

You can achieve it using below solution. In between, I got the guidance from ONE OF THE BEST BOOK I HAVE READ IN LONG LONG TIME. Book is "Inside the Microsoft Build Engine" written by Sayed Ibrahim Hashimi and William Bartholomew. Book goes through the detail in excellent way.

Create a msbuild proj file as shown below

<?xml version="1.0" encoding="utf-8"?>

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="TransformAll">

  <UsingTask TaskName="TransformXml"  AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>

  <PropertyGroup>
    <DestDirectory>C:\Temp\DeployPackage\TRANSFORM_CONFIGS\</DestDirectory>
  </PropertyGroup>

  <ItemGroup>
    <TransformFiles Include="$(FilesToTransform)"/>
  </ItemGroup>

  <Target Name="TransformAll" DependsOnTargets="ValidateSettings">
    <MakeDir Directories="$(DestDirectory)"/>
    <TransformXml Source="..\web.config"
                  Transform="%(TransformFiles.Identity)"
                  Destination="@(TransformFiles->'$(DestDirectory)%(Filename).transformed.config')" />
  </Target>

  <Target Name="ValidateSettings">
    <Error Text="FilesToTransform cannot be empty"
           Condition=" '$(FilesToTransform)'=='' "/>
    <Error Text="Couldn't find transform file at [%(TransformFiles.Fullpath)]"
           Condition =" !Exists('%(TransformFiles.Fullpath)') "/>
  </Target>

</Project>

After adding the above proj file and adding your environment specific files in a folder, simply run the below through msbuild accessible command line

msbuild transform.proj /t:TransformAll /p:FilesToTransform="Lab.config;Test.config;Live.config"

Hope this helps. Don't forget to buy/refer "Inside teh Microsoft Build Engine" book.

like image 92
DotNetInfo Avatar answered Sep 17 '22 19:09

DotNetInfo