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:
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>