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

Maybe resolved itself, after resetting emulator and couple restarts - will let you know
@MillerMark A few weeks ago you tweeted that something huge/incredible was coming....what is/was it? (I am hoping s……
Oddly, it won't hit breakpoints in XF .net standard 2 project now either
@JamesMontemagno Updated to 15.7 preview 2 Visual Studio - now having lots of odd thread issues when starting debug……