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"

2 comments:

  1. Thanks a lot for sharing this!!

    ReplyDelete
  2. Thanks for publishing this Libran, I was missing the second set of parameters you mentioned (/p:UseWPP_CopyWebApplication=True /p:PipelineDependsOnBuild=False ).

    Also, hopefully this will help anyone else in the same situation as me. The modifications to the project file (.csproj or .vbproj) mentioned actually caused an error for me. I noticed this only because my solution had two projects and the project that I hadn't modified yet, was building successfully. Once I removed the new Target you suggested the solution built and dropped the files I was expecting. Our build does all three environments (DEV, TEST, PROD) at once so we're sure that we have the same binaries in each environment, we just needed the transformed config files and this does it! Thanks!

    ReplyDelete