Easily switching between configuration files with MSBuild

A couple of days ago i wrote about Easily switching between App.Config files with MSBuild. Christophe Gijbels, a fellow compuwarrior, pointed out that developers usually need to copy more than a single App.Config file… I would propose to add a Folder for each Customer that contains all the specific configuration files. Eg:

screenshot of solution explorer with proposed folder structures

Now i have to configure MSBuild so that the right files are copied into the OutDir:

<!-- Define the CustomerPath depending on the choosen Configuration -->
<PropertyGroup  Condition=" $(Configuration) == 'Customer1 Debug' ">
 <CustomerPath>Customer1</CustomerPath>
</PropertyGroup>
<PropertyGroup  Condition=" $(Configuration) == 'Customer2 Debug' ">
 <CustomerPath>Customer2</CustomerPath>
</PropertyGroup>

<!-- Define AppConfig in the CustomerPath  -->
<PropertyGroup>
 <AppConfig>$(CustomerPath)\App.config</AppConfig>
</PropertyGroup>

<!-- Find all files in CustomerPath, excluding AppConfig -->
<ItemGroup>
<CustomerFiles Include="$(CustomerPath)\*.*" Exclude="$(CustomerPath)\App.config" />
</ItemGroup>

<Target Name="AfterBuild">
<Copy SourceFiles="@(CustomerFiles)" DestinationFolder="$(OutDir)" SkipUnchangedFiles="true"/>
</Target>

This entry was posted on Saturday, March 22nd, 2008 at 18:40 and is filed under Visual Studio. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.