Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TFS 2012 and web.config transforms

I am trying to have my TFS Build create the web.config transform associated with the configuration I selected for my build. When I run the build I check the web.config file no transforms have been applied. When I a publish from VS2012 the transform works correctly.

I have set up TFS 2012 (Update 2), and have a separate server for builds. I don't have VS2012 installed on the build server, but I copied the C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\ Web and WebApplications folders and files from my dev machine to the build server.

I have created some configurations in my project, and have added some tranforms to the associated web.{configname}.config.

I have created a build and set the Items to Build - Configurations to Build to one of the configurations in my project. I noticed that it only has Debug and Release, it didn't have any of the configurations I created. (Side question: Is that correct, or should it show all the configurations I created?)

So I run a build and check the output folder and the web.config has not applied the transforms. Is there anything else I need to do?

like image 486
Nathan Greenway Avatar asked May 01 '13 02:05

Nathan Greenway


People also ask

What is Web config transform?

A Web. config transformation file contains XML markup that specifies how to change the Web. config file when it is deployed. You can specify different changes for specific build configurations and for specific publish profiles.

How do I create a new transformation in Web config?

If you have a web application project, Right-click on web. config and choose Add Config Transform. This will add any config transforms that are missing from your project based on build configurations (i.e. if you have Production and Staging build configs, both will get a transform added).

What is Xdt transform in Web config?

A transform file is an XML file that specifies how the Web. config file should be changed when it is deployed. Transformation actions are specified by using XML attributes that are defined in the XML-Document-Transform namespace, which is mapped to the xdt prefix.


2 Answers

Just throwing /p:TransformConfigFiles=true on there won't actually do anything.

You also need to add this target to the project file:

<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> 

This is my source: http://blog.degree.no/2012/03/automatic-config-transformations/

like image 108
David De Sloovere Avatar answered Sep 17 '22 10:09

David De Sloovere


You can type-in the name of Configuration in "Items to Build->Configurations to build" list.

If that doesn't help, try to add following MSBuild argument: /p:TransformConfigFiles=true (3. Advanced -> MSBuild Arguments)

like image 40
mukala Avatar answered Sep 20 '22 10:09

mukala