Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

app.config Transformations

I'm a huge fan of the addition of web.config transformations in Visual Studio 2010. See also Scott Hanselman's recent talk at MIX2011.

What sucks is that this functionality (appears at least) to only be available to web projects.

In our solution we have several Windows Services that connect to a different database dependant on the environment they are deployed under.

Has anyone come up with a nice, tidy way of achieving similar 'app.config transformation' functionality?

Note: We are using TFS 2010 to build our solutions in a Continuous Integration manner.

like image 491
isNaN1247 Avatar asked May 31 '11 11:05

isNaN1247


People also ask

What is config transformation?

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 add config transform?

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

You can use the XML transformation functionality with any XML file - we do this all the time. It's available via an MSBuild task.

Try adding the following to your build script:

<UsingTask TaskName="TransformXml"            AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>  <TransformXml Source="Path\To\Your\Xml.config"               Transform="Path\To\Your\Xml.$(Configuration).config"               Destination="Path\To\Your\Output.config" /> 
like image 128
Luke Bennett Avatar answered Sep 27 '22 22:09

Luke Bennett


I realize you already have an answer, but I stumbled across SlowCheetah this morning which is the best implementation I've seen to date. There is also a blog post on getting this running from a CI server.

like image 43
John Laffoon Avatar answered Sep 28 '22 00:09

John Laffoon