You can achieve this using the solution below. Between them, I received guidance from ONE OF THE BEST BOOK I READ IN LONG LONG TIME. Book Inside Microsoft Build Engine , written by Sayed Ibrahim Hashimi and William Bartholomew. The book looks through the details perfectly.
Create the msbuild project 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 to the folder, simply run the msbuild command line below.
msbuild transform.proj /t:TransformAll /p:FilesToTransform="Lab.config;Test.config;Live.config"
Hope this helps. Do not forget to buy / link to the book "Inside the Microsoft Build Engine."
source share