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

The Most Promising Open Source Projects to Watch for in 2018
Relaxing day, catching up on .NET CORE 2 release information. #Microsoft #AspNetCore
Retweeted by @dyardy .@terrajobst & @runfaster2000 demo features of #dotNET Standard on @ch9! Watch:
Retweeted by @dyardy Now on the latest Xamarin Show Snack Pack: Optimized Lists w/ DataTemplate Selectors in Xamarin.Forms,……
Retweeted by @dyardy CodeRush for Roslyn 17.1.8 is Available