In the Life of a TFS Configuration Manager Part 3: Configuration Transforms and Visual Studio Installer Projects

In part 2, I described how to add configuration transforms for non-web projects. Now comes the really difficult part – making it work with Visual Studio Installer projects. The problem is that installer projects include the untransformed App.config rather than the transformed <YourProgram>.exe.config. So we have to make a new copy of the transformed file and include that in the installer project.

1. Edit TransformFiles.targets in the following way. Below

<TransformXml Source="@(_AppConfigToTransform->'%(FullPath)')"
              Condition=" Exists('%(RelativeDir)%(Filename).$(Configuration)%(Extension)') " />

add the following:

<TransformXml Source="@(_FilesToTransformNotAppConfig->'%(FullPath)')"
              Condition=" Exists('%(RelativeDir)%(Filename).$(Configuration)%(Extension)') " />

This will create a file called app.transformed.config.

2. In your installation project, right-click Primary output from your project and select Exclude Filter. Add App.config. This prevents the untransformed App.config to be added to the installation package.

3. To add the transformed configuration file, right-click on the installer project and select Add –> File… Select app.transformed.config. Select it and change the TargetName property to <YourProgram>.exe.config.

The only problem now is that app.transformed.config is write protected during the build, so TransformFiles.targets will fail (“Could not write Destination file: Access to the path ‘…\app.transformed.config’ is denied.”). I solved this with a pre-build event command:

ATTRIB -R $(ProjectDir)app.transformed.config

Now build the installation package and test it.


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.