Transforming External Configuration Files - Visual Studio 2010

Overview

When externalizing configurations settings using the configSource attribute, the web.config transformations don't apply. This article describes a work-around.

<connectionStrings configSource="App_Config\ConnectionStrings.config" />

Solution

1. Create ConnectionStrings.BuildConfigName.config for each build configuration

2. Add a post-build event using the following code.

copy /y "$(ProjectDir)App_Config\ConnectionStrings.$(ConfigurationName).config" "$(ProjectDir)App_Config\ConnectionStrings.config"