Tweet config transform to support non-web.config files and non-Web project

[Update] There is a VS plugin called SlowCheetah to extend native config transform. To make it CI friendly, you need to copy the extension targets file from %LOCALAPPDATA%\Microsoft\MSBuild\SlowCheetah\v1\ to you source control folder then add this parameter to msbuild.

<exec program="${tools.msbuild.console}"
workingdir="${dir.project.ui}"
>
<arg value="/p:Configuration=${env}" />
<arg value="/p:OutDir=${dir.release}\Client.Admin\${env}\" />
<arg value="/p:SlowCheetahTargets=${tools.SlowCheetah.Transforms.targets}" />
</exec>

Right now the config transform feature in VisualStudio only available for WebProject. No luck for non-web project, like, WPF/Silver light project.

Even in WebProject, this transform is limited to web.config only.

Let’s tweet it to make support more.

Step 1, grab this msbuild extension file, put it into your path, I saved it into my {solution.dir}/build folder, then check into source control.

edit project file:

Make your config file transformable, in my case, log4net.config:

Add this transformfiles.targets file.

Step 2, create different copies of transform files for each configuration, set transform rule in it, this is a simple replace:

Build, check output folder. You might want to set “Copy to Output Directory” property to “Do not copy” because config transform is taking over this process.

Step3, make those files look nested in Visual Stuido, open project file again, add this:

WPF/Silverlight project can use the same tweet.

Extra:

A fancy transform, remove-all and insert, really powerful:


        Communications General

Unfortunately, this kind of tweet only works for TRANSFORM_ON_BUILD, while DEPLOY PACKAGE and PUBLISH won’t trigger transform in current version of VS2010.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s