The goal is to have TFS build and deploy 2+ different configurations, and have the web.config transform files include the intended content in their output. This in an ASP.NET MVC project.
Web.Debug.Config - see on PasteBin.
Web.Release.Config - see on PasteBin
The 2 transformed config files have their Build Action set to None. This was modified because all 3 web.*.config files were being included in the deployment.
TFS is configured correctly to build and deploy both configurations. It deploys to the 2 drop locations as expected. There are no MSBuild Arguments specified in the build definition.
Problem: The 2 built and deployed web sites have the same web.config file. Basically it's as if the transformed files did not exist.
Expected: the changes specified (xdt:Transform="Replace"
and xdt:Transform="Remove"
) would be present in the web.config files.
How can you configure your project or TFS to ensure the web.config transformations are processed and their outputs deployed to the correct deployment locations? What else can I check/modify?
xdt
attributes being misused or missing?If I'm missing any important information, please leave a comment, and I'll include any more relevant information!
Previously I had been doing something similar to the other answers. However, I just found what seems to be a better solution to this problem. Just add "/p:UseWPP_CopyWebApplication=true /p:PipelineDependsOnBuild=false" to your MSBuild arguments. I just tried this out on one of my TFS builds and it works just fine.
I found this great tip here: http://www.andygeldman.com/index.php/2011/10/web-and-app-config-transformations-with-tfs-build.
Here's what I've been using. The current TransformXml task has a bug where it leaves files open. Read more here.
You can call this task and deploy for each configuration you're working with.
<Target Name="TransformWebConfig">
<PropertyGroup>
<_tempSourceFile>$([System.IO.Path]::GetTempFileName())</_tempSourceFile>
<_tempTransformFile>$([System.IO.Path]::GetTempFileName())</_tempTransformFile>
</PropertyGroup>
<Copy SourceFiles="$(_websiteDirectory)\Web.config" DestinationFiles="$(_tempSourceFile)"/>
<Copy SourceFiles="$(_websiteDirectory)\Web.$(_transformConfiguration).config" DestinationFiles="$(_tempTransformFile)"/>
<MSBuild.Community.Tasks.Attrib Files="$(_websiteDirectory)\Web.config" ReadOnly="false" />
<TransformXml Source="$(_tempSourceFile)"
Transform="$(_tempTransformFile)"
Destination="$(_websiteDirectory)\Web.config"
StackTrace="false" />
</Target>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With