TFS Build 2015 Not Transforming Web.Config

The following is the solution that addressed this problem.  While setting up a project for TFS build, I came across issues with the build system not transforming my web.config to different configurations.  i.e. I want my web.config to be transformed with web.config.release upon build/publish.

I found the following solution that worked for me.

Within Visual Studio, unload the web project (in this case I am working with a web application), scroll to the bottom and add the following task.  On the build server you can ensure that the path is valid and it is referencing the most appropriate version.  The UsingTask imports the TransformXml method from Microsoft.Web.Publishing.Tasks.dll

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

<Target Name="ApplyTransform" Condition="Exists('Web.$(Configuration).config')">
  <TransformXml Source="web.config" Transform="Web.$(Configuration).config" Destination="Web.config" />

Then within the BeforeBuild Target add

<Target Name="BeforeBuild">
    <Exec Command="attrib -r Web.config" />
    <CallTarget Targets="ApplyTransform" />


Exec removes the read-only attribute from the web.config file and the CallTarget will ApplyTransform target







comments powered by Disqus


Recent Tweets

Dinner time?
Retweeted by @dyardy These 10 companies control everything you buy
Retweeted by @dyardy LED bulbs contributed to a reduction of 570 million tons of carbon dioxide emissions in 2017—equivalent to closing……
I would like to update my profile/email address on Xamarin University. Where can I do this?