Monday, December 29, 2014

TFS2013 Web.Config Transformation in Build

Hi
i have been looking around how to create web.config transformation when using tfs build.
there are 3 options:
  • Use publish profile -         this is done by creating a publish profile (right click on the project and select publish), then add to the build definition, "MSBuild Arguments"
         /p:DeployOnBuild=true /p:PublishProfile=<ProjectLocation>\Properties\PublishProfiles\Test.pubxml
  • Add "xmlTransform" task to the csproj -  open the csproj file for edit (Unload and edit) and add right before the end
<Target Name="TransformConfigFiles" AfterTargets="AfterBuild" Condition="'$(TransformConfigFiles)'=='true'">
    <ItemGroup>
      <DeleteAfterBuild Include="$(WebProjectOutputDir)Web.*.config" />
    </ItemGroup>
    <TransformXml Source="Web.config" Transform="$(ProjectConfigTransformFileName)" Destination="$(WebProjectOutputDir)Web.config" />
    <Delete Files="@(DeleteAfterBuild)" />
</Target>
          in order to control this, you need to add to the build definition, "MSBuild Arguments"
          /p: TransformConfigFiles=true
  • Force MSBuild to run Config transformation - this is done by add to the build definition, "MSBuild Arguments"
          /p:UseWPP_CopyWebApplication=True /p:PipelineDependsOnBuild=False




just don't forge, if you are using TFS2013 with old build templates (2010/2012) you will also need to add "/p:VisualStudioVersion=12.0"